2017-02-06 9 views
0

dashboard.service.tsUnbehandelte Versprechen Ablehnung: Kein Provider für AuthHttp! ; Zone: Winkel in angular2-jwt

import { Injectable } from '@angular/core'; 
import { Http, Response, Headers, RequestOptions } from '@angular/http'; 
import { Observable }  from 'rxjs/Observable'; 
import { AuthHttp } from 'angular2-jwt'; 
import 'rxjs/add/operator/map'; 
import 'rxjs/add/operator/catch'; 

constructor (private http: Http,private authHttp: AuthHttp) {} 

Wenn ich dies tun gibt es einen Fehler Error: Uncaught (in promise): Error: DI

app.module.ts

import { HttpModule } from '@angular/http'; 
import { AuthModule } from 'angular2-jwt'; 
. 
imports: [ 
    HttpModule, 
    AuthModule 
], 

Wie ich dieses Problem lösen ?

+0

Haben Sie die Httpmodule in Ihrem ngmodule importiert? Haben Sie AuthHttp als Provider in Ihrem ngModule festgelegt? :) – Alex

+0

nein .............. –

+0

Ich aktualisiere meine Frage und füge app.module.ts –

Antwort

2

versuchen dieses

import { AUTH_PROVIDERS } from 'angular2-jwt'; 

@NgModule({ 
    imports: [ 
     BrowserModule, 
     FormsModule, 
     HttpModule, 
    ], 
    providers: [ 
     ...AUTH_PROVIDERS, 
     // other providers 
    ] 
}) 

export class AppModule { } 

Option 2

import { AuthModule, AuthConfigConsts} from 'angular2-jwt'; 

const authConfig: IAuthConfig = { 
    headerName: AuthConfigConsts.DEFAULT_HEADER_NAME, // change to your header name 
    headerPrefix: AuthConfigConsts.HEADER_PREFIX_BEARER, // or null or something else 
    tokenName: AuthConfigConsts.DEFAULT_TOKEN_NAME, // change to your token name 
    tokenGetter:() => localStorage.getItem(authConfig.tokenName) as string, 
    noJwtError: false, 
    noClientCheck: false, 
    globalHeaders: [], 
    noTokenScheme: false 
}; 

@NgModule({ 
    imports: [ 
     BrowserModule, 
     FormsModule, 
     HttpModule, 
     AuthModule.forRoot(authConfig) 
    ], 
}) 

export class AppModule { } 
+0

funktioniert nicht ..... –

+0

Ich aktualisiere meine Frage und füge app.module.ts –

+1

warte eine Minute! –

Verwandte Themen