Reputation: 16629
I'm getting the following error when I try to run my ionic2 app (Typescript)
ORIGINAL EXCEPTION: No provider for User! (BeerSearch -> User)
Following is my code
#providers/beer_search/BeerSearch
import { User } from '../user/user';
......
@Injectable()
export class BeerSearch {
constructor(private http: Http, user: User, config: Config) {
this.headers = new Headers();
this.headers.append('Access-Token', user.getAccessToken())
}
}
#providers/user/user
.....
@Injectable()
export class User {
accessToken: string;
constructor(private http: Http) {
this.accessToken = '<Some token>';
}
getAccessToken(){
return this.accessToken;
}
}
I cannot find what I'm doing wrong here , and this also doesn't give any errors with typescript in compile time. I'm getting this error only in runtime.
Upvotes: 0
Views: 66
Reputation: 23516
You can call services in services in services in services, if you want that. That's no problem at all. You just need to add them either to the bootstrap
providers array
bootstrap(App, [..., User, BeerSearch]);
or to the root component's providers
array.
@Component({
...,
providers: [..., User, BeerSearch]
})
export class FooComponent { ... }
Otherweise they won't get resolved like you're just experiencing
Upvotes: 1