首页 > 解决方案 > 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

太感谢了。安德烈亚

标签: angulartypescriptreduxngrx

解决方案


您应该在管道函数中使用 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


推荐阅读