I have 5 api calls in a page. some apis take 20 sec to give response. some take 30 sec to give response. some take 10 sec so, when first api gives its response, first api sets l
You can use rxjs forkjoin for the same. Forkjoin waits for all the request is complete and return the response when all the api call complete. Here is the example.
**component.ts**
isLoading: boolean;
constructor(private apiCallService: ApiSErvice) {}
ngOnInit() {
this.isLoading = true;
this.apiCallService.multipleApiCallFunction().subscribe(response => {
this.isLoading = false;
})
}
**ApiService.service.ts**
import { Observable, forkJoin } from 'rxjs';
multipleApiCallFunction() : Observable{
const api1 = this.http.get('apiurl-1');
const api2 = this.http.get('apiurl-2');
const api3 = this.http.get('apiurl-3');
const api4 = this.http.get('apiurl-4');
return forkJoin([api1, api2, api3, api4]);
}