Join Angular Observables

Posted: 8/17/2017 4:11 PM

If you have multiple observables that you want to execute simultaneously, and be notified when they've completed, you use the Observable.forkJoin() function, passing it an array of Observables:

const observable1 = this.http.get('url1.html');
const observable2 = this.http.get('url2.html');

Observable.forkJoin([observable1, observable2]).subscribe(results => {
  const results1 = results[0]; // observable1 results
  const results2 = results[1]; // observable2 results

  this.processResults1(results1);
  this.processResults2(results2);
});