I'm a bit late to the party but I finally took out the time to learn RxJS and already in love with it ❤️.
What I did
I was wondering, there has to be something like Promise.all
in RxJS and here's what I came up with
import { ajax } from 'rxjs/ajax';
import { of } from 'rxjs';
const myObs = of([
ajax('https://jsonplaceholder.typicode.com/users/1'),
ajax('https://jsonplaceholder.typicode.com/posts/1')
]);
// now myObs is of the type Observable<Observable<AjaxResponse>[]>
// for some reason I don't feel too good about this
myObs.subscribe(function(value) {
/**
* here I get an array of 2 observables which I have to
* loop over and subscribe to each of the observables
*/
console.log('emitted value:', value);
})
What I need
So, my question is, is there any better way of doing what I'm trying to do?
Thanks a lot in advance!
Top comments (4)
combineLatest
has a very similar signaturelearnrxjs.io/learn-rxjs/operators/...
What you want is forkJoin
You can use for forkJoin for this
Thanks, that’s exactly what I needed 👍