1

你好,我有效果,点击按钮后调度新的动作来创建一些东西,

@Effect({dispatch: false})
createSomething$ = this._actions$.pipe(
    ofType(
        clientsActions.Create),
    mergeMap((action) => this._service.add(action.payload)
        .pipe(
            tap(() => this._router.navigate(['somewhere'])),
            catchError(error => of())
        ))
);

这运作良好,效果发送请求并重定向,但现在我想添加,来自根模块中的其他类的操作,但是,当我尝试做类似的事情时

@Effect({dispatch: false})
createSomething$ = this._actions$.pipe(
    ofType(
        clientsActions.Create),
    mergeMap((action) => this._service.add(action.payload)
        .pipe(.map(() => ({type: this.otherActions.doAction),
            tap(() => this._router.navigate(['somewhere'])),
            catchError(error => of())
        ))
);

这不起作用,其他操作什么都不做,甚至没有在开发工具中显示,现在我很困惑发生了什么。我也尝试过 concatMap 等。

4

1 回答 1

0

使用 MergeMap 并返回 Array [{type:actionType}]

@Effect({dispatch: false})
createSomething$ = this._actions$.ofType(clientsActions.Create)
.pipe(
    mergeMap((action) => this._service.add(action.payload).pipe(
        mergeMap(() => ([{type: this.otherActions.doAction}]),
        tap(() => this._router.navigate(['somewhere'])),
        catchError(error => of())
        ))
);
于 2019-03-14T09:28:14.397 回答