I used \"Ionic Loading Controller\" to show a spinner until the data is retrieved then it calls \"dismiss()\" to dismissed it. it works fine, but sometimes when the app alre
My solution for this problem, was to set a status variable. Here it is:
@Injectable()
export class LoaderSerive {
private status: 'pending' | 'dismissed' | 'present' = 'dismissed';
constructor(public loadingCtrl: LoadingController) {}
public show() {
if (this.status === 'present') {
this.hide();
}
this.status = 'pending';
this.loadingCtrl.create({
id: 'spoon-indicator-1',
spinner: null,
message: `
`,
duration: 6000
})
.then((loader) => loader.present())
.then(() => {
if (this.status === 'pending') {
this.status = 'present';
} else {
this.hide();
}
});
}
public hide() {
this.loadingCtrl
.dismiss(null, undefined, 'spoon-indicator-1')
.catch((err) => Utilities.log('Loader error!', err))
.then(() => this.status = 'dismissed');
}
}