tubu13
tubu13

Reputation: 934

angular2-jwt: No provider for AuthConfig

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

Answers (2)

Thierry Templier
Thierry Templier

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

Michael Desigaud
Michael Desigaud

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

Related Questions