When attempting to run my Ionic2 app in Typescript, I encountered the following error:
ORIGINAL EXCEPTION: No provider for User! (BeerSearch -> User)
Here is the relevant code snippet:
#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 am unsure of what mistake I have made here, especially since there are no compile-time errors indicated by Typescript. The issue only arises at runtime.