Multiple Observable results get in Single Subscriber like Promise.all() Angular: rxjs

Shivam Gupta
2 min readJul 30, 2019

Suppose we need to hit multiple APIS and need their response in a single success so how to do that while using Observable pattern. First, let's take an example of promise -

Multiple promise response capture while all completed

Observable Way

Now if we are using angular and using HttpClient so -

this.http.get() : returns Observable . So if we have multiple API’s calls we want when all API got success then response capture.

we need to import forkJoin

import { Observable, forkJoin } from ‘rxjs’;

import { HttpClient } from ‘@angular/common/http’;

forkJoin: returns multiple Observable

Steps:

  1. Create a function and its return Type should be Array Of Observable

requestDataFromMultipleSources(): Observable<any[]> {….}

2. return forkJoin( /* array of all Observables */)

3. Subscribe this method: requestDataFromMultipleSources().subscribe(res => console.log(res) )

Thanks for reading. Please give a clap if you like this post. Give your comments below.

--

--

Shivam Gupta

Full Stack Engineer (Web/App) working on different JS Technologies & frameworks— Angular, Node, Typescript, Ionic, Firebase, AWS, ElK...Love to write cool stuff