Angular 在装饰器中不支持函数表达式,请考虑将函数表达式转换为导出函数。

Angular 在装饰器中不支持函数表达式,请考虑将函数表达式转换为导出函数。,angular,typescript,Angular,Typescript,我遇到了这个错误:“AppModule”的模板编译过程中出错 “ɵ0”中的装饰器不支持函数表达式 “ɵ0”包含app/app.module.ts(40,22)处的错误 考虑将函数表达式转换为导出函数。 它说位于这段代码中: @NgModule({ declarations: [ AppComponent, HomeComponent, ProfileComponent, LoginComponent, RegisterComponent, Lo

我遇到了这个错误:“AppModule”的模板编译过程中出错 “ɵ0”中的装饰器不支持函数表达式 “ɵ0”包含app/app.module.ts(40,22)处的错误 考虑将函数表达式转换为导出函数。

它说位于这段代码中:

@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    ProfileComponent,
    LoginComponent,
    RegisterComponent,
    LoadingOverlayComponent,
    LoadingComponent,
    TrendsComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    ReactiveFormsModule,
    HttpClientModule,
    JwtModule.forRoot({
      config: {
        tokenGetter: function tokenGetter() {
          return localStorage.getItem('token');
        }
      }
    })
  ],
  providers: [
    { provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true },
    { provide: HTTP_INTERCEPTORS, useClass: RefreshJwtInterceptor, multi: true },],
  bootstrap: [AppComponent]
})
export class AppModule { }

我搜索了这个问题,但似乎找不到与我的情况相同的人。

尝试像这样导出内联函数tokenGetter:

导出函数tokenGetter(){
返回localStorage.getItem('token');
}
@NGD模块({
声明:[
应用组件,
HomeComponent,
配置文件组件,
LoginComponent,
注册表组件,
加载覆盖组件,
加载组件,
趋势组件
],
进口:[
浏览器模块,
批准模块,
反应形式模块,
HttpClientModule,
JwtModule.forRoot({
配置:{
令牌获取者
}
})
],
供应商:[
{provide:HTTP_拦截器,useClass:JwtInterceptor,multi:true},
{provide:HTTP_拦截器,useClass:RefreshJwtInterceptor,multi:true},],
引导:[AppComponent]
})
导出类AppModule{}
更多信息,请访问