Reputation: 934
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){
}
}
Upvotes: 3
Views: 1653
Reputation: 202146
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]
})
]
Upvotes: 5
Reputation: 2135
Try to add AuthConfig
as a dependency :
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,AuthConfig]
}),
AuthHttp
]
})
Upvotes: -1