angular - Angular redux @effect:检索有效负载时出错
问题描述
我在使用 ngrx/@effect 检索有效负载时遇到了一些问题
//DELETE TASK
@Effect({ dispatch: false })
deleteTasks$: Observable<Task> = this.actions.ofType(fromActions.DELETE_TASK)
.map((action: fromActions.DeleteTaskAction) => action.payload)
.pipe(
switchMap((payload) =>
this.taskService.DeleteTask(payload).pipe(map(data => {
return data;
},
error => console.log(error)
)))
);
错误:this.actions.ofType(...).map 不是函数
这是项目,
https://stackblitz.com/edit/redux-in-actions?file=src%2Fapp%2Fstore%2Feffects%2Ftask.effects.ts
太感谢了。安德烈亚
解决方案
您应该在管道函数中使用 ofType 方法。例如:
@Effect({ dispatch: false })
getTasks$: Observable<Task[]> = this.actions.pipe(
ofType(fromActions.GET_TASKS),
switchMap(() =>
this.taskService.GetTasks().pipe(map(data => {
return data;
},
error => console.log(error)
)))
)
这是固定示例:Stackblizt
推荐阅读
- browser - 在 Applescript 中检测默认浏览器
- python - 在客户端使用 API 密钥 - 烧瓶 python
- javascript - 如何在 cookie JavaScript 中添加图片?
- javascript - 如何在 NodeJS 中使用 Javascript 窗口?
- java - 如何从 RecyclerView 适配器检索项目计数到另一个活动(不是父活动)?
- database - 创建和管理大量客户定义的数据库
- glsl - glsl - 我可以将常量传递给函数而不将常量复制到参数中吗?
- kotlin - 更改 HttpUrlConnection 的 DNS
- python - 在使用 sqlite3 的 Python 中,使用 commit() 语句将数据插入 SQLITE 不起作用
- visual-studio - 发布扩展时出现错误 VsixPub0004 错误