Gelso77
Gelso77

Reputation: 1895

Angular redux @effect: Error on retriving the payload

I'm having some problems to retrive the payload using 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)
      )))
  );

ERROR: this.actions.ofType(...).map is not a function

this is the project,

https://stackblitz.com/edit/redux-in-actions?file=src%2Fapp%2Fstore%2Feffects%2Ftask.effects.ts

thank you so much. Andrea

Upvotes: 0

Views: 57

Answers (1)

jakubm
jakubm

Reputation: 422

You are supposed to use ofType method inside pipe function. For instance:

@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)
 )))
)

Here is fixed example: Stackblizt

Upvotes: 1

Related Questions