Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  90] [ 3]  / answers: 1 / hits: 82290  / 8 Years ago, wed, february 24, 2016, 12:00:00

In Angular 1.x I would sometimes need to make multiple http requests and do something with all the responses. I would throw all the promises in an array and call Promise.all(promises).then(function (results) {...}).



Angular 2 best practices seem to point towards the use of RxJS's Observable as a replacement to promises in http requests. If I have two or more different Observables created from http requests, is there an equivalent to Promise.all()?


More From » angularjs

 Answers
47

The more straightforward alternative for emulating Promise.all is to use the forkJoin operator (it starts all observables in parallel and join their last elements):





A bit out of scope, but in case it helps, on the subject of chaining promises, you can use a simple flatMap : Cf. RxJS Promise Composition (passing data)


[#63178] Tuesday, February 23, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
morrismilom

Total Points: 230
Total Questions: 96
Total Answers: 114

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
;