angular2-jwt - 调用函数 'provideAuth',不支持函数调用
angular2-jwt - Calling function 'provideAuth', function calls are not supported
我在我的 angular2/4 应用程序中使用 angular2-jwt 插件进行身份验证。但是在设置环境后我可以使用它一次。重建项目后出现以下错误。
错误:
ERROR in Error encountered resolving symbol values statically. Calling function 'provideAuth', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in /home/user/projects/project/src/app/app.module.ts, resolving symbol AppModule in /home/user/projects/project/src/app/app.module.ts
我的app.module.ts
@NgModule({
imports: [
HttpModule,
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
BsDropdownModule.forRoot(),
TabsModule.forRoot(),
ChartsModule,
LaddaModule,
FormsModule,
ToasterModule
],
declarations: [
AppComponent,
LoginComponent,
FullLayoutComponent,
AsideToggleDirective,
DashboardMenuComponent,
],
providers: [
{
provide: LocationStrategy,
// useFactory: authHttpServiceFactory,
// deps: [Http, RequestOptions],
useClass: HashLocationStrategy,
},
AuthenticationService,
AuthGuard,
Auth,
AuthHttp,
provideAuth({
headerName: 'Authorization',
headerPrefix: 'bearer',
tokenName: 'token',
// tokenGetter: (() => localStorage.getItem('token')),
globalHeaders: [{'Content-Type': 'application/json'}],
noJwtError: true
})
],
bootstrap: [AppComponent]
})
出现此错误后,我导出函数如下:
export function authHttpServiceFactory(http: Http, options: RequestOptions) {
return new AuthHttp(new AuthConfig(), http, options);
}
and imported in providers but the error will be:
ERROR Error: Uncaught (in promise): Error: No provider for AuthHttp!
在提供商中添加 AuthHttp 后,错误将是:
ERROR Error: Uncaught (in promise): Error: No provider for AuthConfig!
提供为
providers: [
AuthHttp,
{
provide: AuthHttp,
useFactory: authHttpServiceFactory,
deps: [Http, RequestOptions]
}
]
export function authHttpServiceFactory(http: Http, options: RequestOptions) {
return new AuthHttp(new AuthConfig({
headerName: 'Authorization',
headerPrefix: 'bearer',
tokenName: 'token',
// tokenGetter: (() => localStorage.getItem('token')),
globalHeaders: [{'Content-Type': 'application/json'}],
noJwtError: true
}), http, options);
}
我在我的 angular2/4 应用程序中使用 angular2-jwt 插件进行身份验证。但是在设置环境后我可以使用它一次。重建项目后出现以下错误。
错误:
ERROR in Error encountered resolving symbol values statically. Calling function 'provideAuth', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in /home/user/projects/project/src/app/app.module.ts, resolving symbol AppModule in /home/user/projects/project/src/app/app.module.ts
我的app.module.ts
@NgModule({
imports: [
HttpModule,
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
BsDropdownModule.forRoot(),
TabsModule.forRoot(),
ChartsModule,
LaddaModule,
FormsModule,
ToasterModule
],
declarations: [
AppComponent,
LoginComponent,
FullLayoutComponent,
AsideToggleDirective,
DashboardMenuComponent,
],
providers: [
{
provide: LocationStrategy,
// useFactory: authHttpServiceFactory,
// deps: [Http, RequestOptions],
useClass: HashLocationStrategy,
},
AuthenticationService,
AuthGuard,
Auth,
AuthHttp,
provideAuth({
headerName: 'Authorization',
headerPrefix: 'bearer',
tokenName: 'token',
// tokenGetter: (() => localStorage.getItem('token')),
globalHeaders: [{'Content-Type': 'application/json'}],
noJwtError: true
})
],
bootstrap: [AppComponent]
})
出现此错误后,我导出函数如下:
export function authHttpServiceFactory(http: Http, options: RequestOptions) {
return new AuthHttp(new AuthConfig(), http, options);
}
and imported in providers but the error will be:
ERROR Error: Uncaught (in promise): Error: No provider for AuthHttp!
在提供商中添加 AuthHttp 后,错误将是:
ERROR Error: Uncaught (in promise): Error: No provider for AuthConfig!
提供为
providers: [
AuthHttp,
{
provide: AuthHttp,
useFactory: authHttpServiceFactory,
deps: [Http, RequestOptions]
}
]
export function authHttpServiceFactory(http: Http, options: RequestOptions) {
return new AuthHttp(new AuthConfig({
headerName: 'Authorization',
headerPrefix: 'bearer',
tokenName: 'token',
// tokenGetter: (() => localStorage.getItem('token')),
globalHeaders: [{'Content-Type': 'application/json'}],
noJwtError: true
}), http, options);
}