How can I display a loading on the screen, during the request time of 2 or more requestses with Ionic 3 and / or Angular 4?
I have tried to make the loading of the two requests, but whenever the fastest request ends, it hides the loading, without the second one being finalized.
ionViewDidLoad() {
this.getSummary(parametros);
this.getHeatmap(parametros);
}
getSummary() {
this.loadingService.showLoader(this.constants.MSG_LOADING);
this.remedyProvider.getSummaryByDate().subscribe(
(response) => {
/// do something
}, (error) => {
this.showSummary = false;
console.log('Backend returned error was: ${error}');
this.loadingService.hideLoader();
}, () => {
console.log('get heatmap complete');
this.loadingService.hideLoader();
}););
}
getHeatmap() {
this.loadingService.showLoader(this.constants.MSG_LOADING);
this.remedyProvider.getHeatmap().subscribe(
(response) => {
//do something
}, (error) => {
console.log('Backend returned error was: ${error}');
}, () => {
console.log('get heatmap complete');
this.loadingService.hideLoader();
});
}
Code of LoadingProvider (loadginService):
export class LoadingProvider {
loader: any = null;
constructor(private _loadingController: LoadingController) {
}
private showLoadingHandler(message) {
if (this.loader == null) {
this.loader = this._loadingController.create({
content: message
});
this.loader.present();
} else {
this.loader.data.content = message;
}
}
private hideLoadingHandler() {
if (this.loader != null) {
this.loader.dismiss();
this.loader = null;
}
}
public showLoader(message) {
this.showLoadingHandler(message);
}
public hideLoader() {
this.hideLoadingHandler();
}
}