【问题标题】:Effect dispatched an invalid action - Actions must be objectsEffect 调度了一个无效的动作 - 动作必须是对象
【发布时间】:2019-11-14 16:07:16
【问题描述】:

当我添加.map(...) 通知服务和关闭对话框功能时,我得到了错误。

设置这个的正确方法是什么? 这是我的效果

@Effect()
    addNewUser$ = this.actions$.pipe(
     ofType(actions.UserActionTypes.addNewUser),
        mergeMap((user: actions.addNewUser) =>
          this.userService.createUser(user.user).pipe(
             map(() => {
               new actions.LoadUsers(),
               this.notificationService.success("User added successfully!");  <--- added
               this.dialogRef.closeAll();    <--- added 
             }),
    catchError(error => of(new actions.Error(error.error)))
  )
)

);

我收到错误

core.js:6014 ERROR 错误:Effect "UserEffects.addNewUser$" dispatched an invalid action: undefined

TypeError: Actions must be objects

有什么帮助吗?谢谢

【问题讨论】:

    标签: ngrx ngrx-effects


    【解决方案1】:

    正如错误所说,您应该返回一个操作。 map 没有返回值,因此它将返回 undefined - 导致错误。

    尝试以下方法:

    this.notificationService.success("User added successfully!");  <--- added
    this.dialogRef.closeAll();    <--- added
    return new actions.LoadUsers();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-26
      • 1970-01-01
      • 2017-11-20
      • 2021-04-01
      • 2019-04-26
      • 2020-06-13
      • 2018-03-23
      相关资源
      最近更新 更多