【问题标题】:angular2 - Consider replacing the function or lambda with a reference to an exported functionangular2 - 考虑将函数或 lambda 替换为对导出函数的引用
【发布时间】:2017-08-27 18:13:06
【问题描述】:

尝试更新 angular2 与 cli 一起完全是一场灾难。我试图恢复但不能关于 angular2-cli。现在我的应用程序将无法加载,因为带有 auth0 的 JWT。它曾经工作过。错误如下。

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
          })

【问题讨论】:

  • 你为什么不写localStorage.getItem('id_token')

标签: angular auth0


【解决方案1】:

我遇到了同样的问题,这解决了问题:

  1. 像这样定义您的授权模块:

@NgModule({ providers: [ { provide: AuthHttp, useFactory: authHttpServiceFactory, deps: [Http, RequestOptions] } ] }) export class AuthorizationModule { }

  1. 在同一个文件中的某处导出 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); }

【讨论】:

  • 谢谢! export function authHttpServiceFactory export 并花了几个小时寻找原因。
  • 很高兴它对您有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-01
  • 2017-06-10
  • 1970-01-01
  • 1970-01-01
  • 2017-04-26
  • 2020-09-25
  • 1970-01-01
相关资源
最近更新 更多