1
How can I display a loading on the screen during the request time of 2 or more required with Ionic 3 and/or Angular 4?
I tried to call the loading in the two requests, but whenever the request finishes faster, it already hides the loading, without the second is finished.
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();
}
}