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()
?
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)