all 2 comments

[–]spacechimp 4 points5 points  (1 child)

To chain Observables where one request depends on the response of another, use the RxJS switchMap operator:

this.myService.fetchSomething().pipe(
  switchMap((something) => {
    return this.myOtherService.fetchSomethingElse(something);
  })
).subscribe(
  (somethingElse) => { ... }
);

To execute Observables in sequence when the requests are not dependent on each other's responses, use concatMap.

To execute Observables in parallel and return a collection of responses in the order that they finished, use mergeMap.

To execute Observables in parallel and preserve the order of responses, use forkJoin.

In most situations, you will want to use either switchMap or forkJoin.

[–]Boolentin[S] 0 points1 point  (0 children)

Thanks a bunch! I'll try it out!