Im tying to use the angular2-jwt with my ionic2 application and I keep getting No provider for AuthConfig!
Here is my app.ts:
import {AuthHttp, AuthConfig} from 'angular2-jwt';
import {Http} from 'angular2/http'
@App({
template: '<ion-nav [root]="rootPage"></ion-nav>',
config: {}, // http://ionicframework.com/docs/v2/api/config/Config/
providers: [
provide(AuthHttp, {
useFactory: (http) => {
return new AuthHttp(new AuthConfig(), http);
},
deps: [Http]
}),
AuthHttp
]
})
And im using that on my login.ts page:
import {AuthHttp, AuthConfig} from 'angular2-jwt';
@Page({
templateUrl: 'build/pages/login/login.html',
directives: [IONIC_DIRECTIVES]
})
export class LoginPage {
constructor(private authHttp: AuthHttp){
}
}
It's strange that you define twice the provider for AuthConfig:
providers: [
provide(AuthHttp, {
useFactory: (http) => {
return new AuthHttp(new AuthConfig(), http);
},
deps: [Http]
}),
AuthHttp // <-----------
]
The second will override the first one and expect AuthConfig to be injected in AuthHttp as first parameter. But there is no provider for AuthConfig.
It should work by removing the second AuthHttp, as described below:
providers: [
provide(AuthHttp, {
useFactory: (http) => {
return new AuthHttp(new AuthConfig(), http);
},
deps: [Http]
})
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With