[英]angular ngrx store call multi http service into one effect and dispacth actions
嗨,我需要以并行模式调用多 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 请求的每个 map 之后添加第一个操作员。 当所有 Observable 结束时,forkJoin 会发出。 当您执行 http 请求时,从技术上讲,可观察对象不会结束。 所以第一个操作员完成了这些。
doSearchCliente$ = createEffect(() =>
this.actions$.pipe(
ofType(addCliente),
switchMap(action => {
const cliente$ = this.clienteService.ClienteById(action.id).pipe(
first(),
map(response => addClienteSuccess({ response })),
catchError(() => of(addClienteFailure())));
const listino$ = this.clienteService.ListinoCollection(action.id).pipe(
first(),
map(response => addListinoSuccess({ response })),
catchError(() => of(addListinoFailure())));
return forkJoin([cliente$, listino$]).pipe(
mergeMap(response => [response[0], response[1]])
);
}),
));
你说这个吗?
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$]);
}),
switchMap(response => {
return [response[0]];
})
));
不行: :(
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.