Effect 调度了一个无效的动作 - 动作必须是对象
Effect dispatched an invalid action - Actions must be objects
当我添加 .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 Error: Effect "UserEffects.addNewUser$" dispatched an invalid action: undefined
TypeError: Actions must be objects
有什么帮助吗?谢谢
如错误所述,您应该return执行操作。
map
没有 return 值,因此它将 return undefined
- 导致错误。
尝试以下操作:
this.notificationService.success("User added successfully!"); <--- added
this.dialogRef.closeAll(); <--- added
return new actions.LoadUsers();
当我添加 .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 Error: Effect "UserEffects.addNewUser$" dispatched an invalid action: undefined
TypeError: Actions must be objects
有什么帮助吗?谢谢
如错误所述,您应该return执行操作。
map
没有 return 值,因此它将 return undefined
- 导致错误。
尝试以下操作:
this.notificationService.success("User added successfully!"); <--- added
this.dialogRef.closeAll(); <--- added
return new actions.LoadUsers();