Promise .all() with RxJS

后端 未结 4 2261
死守一世寂寞
死守一世寂寞 2020-12-06 01:14

I\'m writing an app in Angular 2 and I want to execute several http requests and run a function on the responses.

In Angular 1, I would write something like $q

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 01:19

    As @Eric Martinez pointed out, there is forkJoin. forkJoin runs all observable sequences in parallel and collect their last elements.

    Rx.Observable.forkJoin([a,b]).subscribe(t=> {
            var firstResult = t[0];
            var secondResult = t[1];
    });
    

提交回复
热议问题