I have a page which has to be update every minute, but I have several http request. So I'm trying use Interval with zip operator. How Can I combine these two to show my loading "isLoading" after all the request?
This is what I got :
isLoading = true;
source = interval(60000);
ngOnInit(): void {
const responseZipado = zip(
this.monitorService.getSMPPstatus(),
this.homeService.getCampaignsToday(),
this.monitorService.getPerfomance(),
);
responseZipado.subscribe((valores) => {
this.statusSMPP = valores[0],
this.dataSourceToday = valores[1],
this.perfomanceDataSource = valores[2],
});
}
should I use other operator than Zip?
You can use forkJoin for parallel http requests because you need value after loading all requests.
Example:
interval(60000).pipe(
tap(() => this.isLoading = true),
switchMap(() => forkJoin([
this.monitorService.getSMPPstatus().pipe(catchError(error => of(error))),
this.homeService.getCampaignsToday().pipe(catchError(error => of(error))),
this.monitorService.getPerfomance().pipe(catchError(error => of(error))),
])),
).subscribe((valores) => {
this.isLoading = false;
this.statusSMPP = valores[0];
this.dataSourceToday = valores[1];
this.perfomanceDataSource = valores[2];
})