angular - 'auth' 中的装饰器不支持函数表达式

标签 angular ngrx

我正在尝试使用 aot 构建我的 Angular 7 项目,但 aot 抛出以下错误

ERROR in app/app.store.ts(10,25): Error during template compile of 'AppStoreModule'

Function expressions are not supported in decorators in 'auth'
'auth' references 'auth'
  'auth' contains the error at app/state/auth/auth.reducers.ts(12,41)
    Consider changing the function expression into an exported function.

我已经检查了 ngrx reducer 的身份验证,如下所示

export const auth: ActionReducer<any> = (
  state = initialState,
  action: authActions
) => {
  switch (action.type) {
    case Auth.AUTH_REFRESH:
    case Auth.AUTH_LOGIN:
      console.log(" reducer called");
      return Object.assign({}, state);
    case Auth.AUTH_LOGIN_SUCCESS:
      console.log("login success reducer");
      let token = localStorage.getItem("token");
      const decodedToken = helper.decodeToken(token);
      console.log(decodedToken.sub);
      return Object.assign({}, state, {
        currentUser: decodedToken.sub,
        loggedIn: !helper.isTokenExpired(token)
      });

    default:
      return state;
  }
};

这是我的 AppStoreModule

@NgModule({
  imports: [
    StoreModule.forRoot({
      auth,
      app,
      search
    }),
    EffectsModule.forRoot([AuthEffects, AppEffects, SearchEffects])
  ]
})

我不知道代码有什么问题。

最佳答案

这是AOT编译的常见问题,需要将函数从箭头函数更改为命名函数,如here

关于angular - 'auth' 中的装饰器不支持函数表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55677231/

相关文章:

angular - ngx-datatable ERESOLVE 无法解析依赖树

angular - 如何销毁 Angular 中的 localStorage 项?

angular - 如何使用@ngrx/store 获取 State 对象的当前值?

javascript - 在 NgRx 应用程序中对对象使用 Array.reduce 函数

angular - 使用 angularfire2 时要在 ngrx/store 中存储什么?

angular - 安装 ng bootstrap 并编译后,出现此错误

css - ng5-slider - 我们如何更改 slider 事件的背景颜色?

javascript - 如何将数据从一个组件传递到另一个组件以进行编辑表单?

javascript - Angular 4 + Redux(或 ngrx/store)文件夹和文件结构

javascript - 链二选择 rxjs store in Angular Guard