【发布时间】:2020-12-08 00:35:13
【问题描述】:
您好,我需要在并行模式下调用多 http 服务,为此我使用 forkJoin,但完成后它不会调度操作。
doSearchCliente$ = createEffect(() =>
this.actions$.pipe(
ofType(addCliente),
switchMap(action => {
const cliente$ = this.clienteService.ClienteById(action.id).pipe(
map(response => addClienteSuccess({ response })),
catchError(() => of(addClienteFailure())));
const listino$ = this.clienteService.ListinoCollection(action.id).pipe(
map(response => addListinoSuccess({ response })),
catchError(() => of(addListinoFailure())));
return forkJoin([cliente$, listino$]).pipe(
mergeMap(response => [response[0], response[1]])
);
}),
));
有人可以帮我吗?
【问题讨论】:
-
尝试在每个 http 请求的每个映射之后添加第一个操作符。我认为 forkJoin 会在所有 Obs 结束时发出。并且当您执行 http 请求时,可观察的技术不会结束。所以第一个运营商让这些结束
-
我在每个 http 调用一个地图!我不明白你
-
更改 map(response => addClienteSuccess({ response })),for map(response => addClienteSuccess({ response }))、first() 和 map(response => addListinoSuccess({ response })), for map(response => addListinoSuccess({ response })), first(), 并在文件顶部添加 import {first} from 'rxjs/operators'
标签: angular ngrx-store ngrx-effects fork-join