@Effect()
initDomain$: Observable<Action> = this.actions$.pipe(
ofType('INIT_DOMAIN'),
mergeMap((action: any) =>
this.http.get('https://demo.api/url1.php').pipe(
switchMap((data) => [
{type: 'INIT_IT', payload: data}
]),
catchError(() => of({type: 'INIT_IT_FAILED'}))
)
)
);
我有这个角度效果(ngrx),它在继续之前发出1个请求。在继续之前,如何发出两个请求并等待两个响应?我知道forkJoin()就是答案,但是我对它的语法有点迷惑
发布于 2018-07-19 14:30:48
forkJoin(
this.http.get('myUrl'),
this.http.get('myOtherUrl')
)
或者,如果在数组中有一堆可观察对象,您还可以编写
const myArrayOfObservables = [
this.http.get('myUrl'),
this.http.get('myOtherUrl')
];
forkJoin(
myArrayOfObservables
)
这是因为"forkJoin“使用”扩展“(...args)运算符作为其参数。
https://stackoverflow.com/questions/51414921
复制相似问题