【发布时间】:2022-01-06 10:36:28
【问题描述】:
我正在使用 NgRx @Effect,为了达到某些效果,我需要执行 2 个 API 调用:第一个的结果用于第二个,我想用第二个 API 调用调度 Action像payload 这样:
@Effect()
FetchDetails() {
return this.actions.pipe(
ofType(actions.SOME_ACTION),
switchMap((action: SomeAction) => this.myService.getContext()),
switchMap((ctx: Context) => this.myService.fetchDetails(action.id, ctx.requesterType)
.pipe(
map((response: Details) => new SetDetails(response)),
catchError(err => {return of(new SetFetchDetailsError(err))})
)
)
}
像这样使用双 switchMap 我无法访问 action.id 所以我认为我的操作员编排不正确!
【问题讨论】:
标签: angular redux ngrx ngrx-effects switchmap