尝试更新angular2与cli一起完全是灾难。我试图恢复但不能解决angular2-cli问题。现在我的应用程序将无法加载,因为JWT与auth0。它曾经工作过。错误如下。
209:29 is this line:
tokenGetter: (() => localStorage.getItem('id_token')),
但它曾经工作过,它是auth0文档的一部分: https://github.com/auth0/angular2-jwt#basic-configuration
'ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 209:29 in the original .ts file), resolving symbol AppModule in /Users/angular2cliisstupid/Documents/frontend/qta/src/app/app.module.ts`
provideAuth({
headerName: 'Authorization',
headerPrefix: 'bearer',
tokenName: 'token',
tokenGetter: (() => localStorage.getItem('id_token')),
globalHeaders: [{ 'Content-Type': 'application/json' }],
noJwtError: true
})
答案 0 :(得分:4)
我遇到了同样的问题,这解决了这个问题:
@NgModule({
providers: [
{
provide: AuthHttp,
useFactory: authHttpServiceFactory,
deps: [Http, RequestOptions]
}
]
})
export class AuthorizationModule { }
在同一个文件中的某处导出authHttpServiceFactory函数
export function authHttpServiceFactory(http: Http, options: RequestOptions) {
return new AuthHttp(new AuthConfig({
tokenName: 'token',
tokenGetter: (() => localStorage.getItem('id_token')),
globalHeaders: [{'Content-Type':'application/json'}],
headerName: 'Authorization',
headerPrefix: 'JWT',
noJwtError: true
}), http, options);
}