1

问题是api.deleteUser返回 null(状态 204),所以用户丢失了。如何将用户(即action.payload)传递给DeleteUserSuccess(user)

@Effect()
public deleteUser$: Observable<Action> = this._actions$
    .ofType(DELETE_USER_PENDING)
    .pipe(
    switchMap((action: IAction<User>) => 
    this.api.deleteUser((action.payload as User).id)),
    map((user: User) => new DeleteUserSuccess(user)),
    catchError((err: Error, caught: Observable<Action>) => {
        console.log(err);
        return caught;
    })
    );
4

1 回答 1

2

我找到了解决方案

@Effect()
    public deleteUser$: Observable<Action> = this._actions$
        .ofType(DELETE_USER_PENDING)
        .pipe(
        switchMap((action: IAction<User>) =>
        this.api.deleteUser((action.payload as User).id).
        map(() => new DeleteUserSuccess(action.payload as User))),
       // map((user: User) => new DeleteUserSuccess(user)),
        catchError((err: Error, caught: Observable<Action>) => {
            // tslint:disable-next-line
            console.log(err);
            return caught;
        })
        );
于 2017-12-15T17:45:56.577 回答