你好,我的效果是点击按钮后调度新的Action来创建内容,
@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等。
答案 0 :(得分:0)
使用MergeMap并返回数组[{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())
))
);