5
votes

I have used two service 1. connection-service and 2. sales-service

The connection-service contains the ip and port information. I need to get the ip and port from the first service to the sales-service. so that i can complete the url used for getting the json.

Removed the coding part here, please take a look at my repo at Update#3

Error I'm getting

2     007892   error    EXCEPTION: No provider for t!                                                                           
3     007893   error    ORIGINAL STACKTRACE:                                                                                    
4     007893   error    Error: No provider for t!                                                                               
    at e.Error (native)                                                                                                         
    at e [as constructor] (http://192.168.1.48:8100/build/main.js:5:4700)                                                       
    at e [as constructor] (http://192.168.1.48:8100/build/main.js:5:9276)                                                       
    at new e (http://192.168.1.48:8100/build/main.js:5:9604)                                                                    
    at t._throwOrNull (http://192.168.1.48:8100/build/main.js:5:26583)                                                          
    at t._getByKeyDefault (http://192.168.1.48:8100/build/main.js:5:26939)                                                      
    at t._getByKey (http://192.168.1.48:8100/build/main.js:5:26494)                                                             
    at t.get (http://192.168.1.48:8100/build/main.js:5:22859)                                                                   
    at e.get (http://192.168.1.48:8100/build/main.js:7:14254)                                                                   
    at e.get (http://192.168.1.48:8100/build/main.js:8:1442)                                                                    
5     007895   error    Uncaught Error: No provider for t!, http://192.168.1.48:8100/build/polyfills.js, Line: 3

My Ionic info

Cordova CLI: 6.3.1
Gulp version: CLI version 3.9.1
Gulp local:
Ionic Framework Version: 2.0.0-rc.1
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Mac OS X El Capitan
Node Version: v6.7.0
Xcode version: Xcode 7.3.1 Build version 7D1014

from the stack trace i understand that i need to use something like providers:[ConnectionService] but i don't know how to use it in Sales-Service provide. Any advise would be helpful. Thank you.

Update #1

I tried injecting both the services in app.module.ts file as given below

  1. providers: [ConnectionService, SalesService] // this works thanks @jmilloy and @camaron.

Update #2

I created a new project and i replicated the error which says

No provider for FirstService!

but in my original project, the error should say

No provider for ConnectionService!

// instead it says

No provider for t! //what is it referring as t?

Update #3 I have uploaded my project in my repo. check it out.

This is my original project repo //Issue solved, had to clean the npm cache.

This is my new project repo //Issue solved based on the answer given

2
Do you have an ionicBootstrap call anywhere? I'm beginning with Angular/Ionic, but in our app.ts we would have have ionicBootstrap(AppModule, [ConnectionService, SalesService]). Or maybe you can add ConnectionService to the bootstrap list?jmilloy
@jmilloy Thanks for the reply, please see my updated question Update#1Darth Ionic

2 Answers

2
votes

Your issue seems to be your SalesService, you are using a provider: [SalesService] on a component? If not you should add the SalesService to your providers: [ConnectionService, SalesService] on your app.module.ts

0
votes

Try

import { Injectable, Inject } from '@angular/core';
import { Http, Headers } from '@angular/http';
import { ConnectionService } from './connection-service';
import 'rxjs/add/operator/map';

@Injectable()
export class SalesService {
  connection:ConnectionService;
  constructor(public http: Http, @Inject(ConnectionService) connection:ConnectionService) {
    this.connection = connection;
    this.http = http;
    this.connection.getConnectionInfo();
  }

  getSalesData(): any {
    return this.http.get("http://"+this.connection.ip+":"+this.connection.port+"/DasherAPI/public/api2/getCompanySalesFull");
  }
}

Check the @Inject on constructor, don't forget the Inject import.