Reputation: 6936
I am currently working on an Ionic2 project. On one page (e.g. PageB) I am showing a Loader (inside ionViewWillEnter() event) till Ajax request success, after that loader.dismiss() called. It is working perfectly. After ajax request User click on something to goto next page(e.g : PageC). But when user comes back from PageC to PageB, loader is again visible.
I want to know if there is any function, so that On PageB load I can know if the page is transitioned from PageC(from history), and prevent loader loading.
Smaple code for PageB is
ionViewWillEnter()() {
this.presentLoading();
}
presentLoading() {
this.loader = this._loadingCtrl.create({
content: "Please wait..."
});
this.loader.present();
}
Upvotes: 0
Views: 48
Reputation: 29614
Instead of putting the ajax request in ionviewWillEnter
you could set the same call and present loading call inside either ngOnInit
or ionViewDidLoad
.
ngOnInit(){
this.presentLoading();
}
These lifecycle hooks are called only once during initial page load.If it makes sense to put the ajax call in this hook, it will provide the same effect and loader will not be shown when user returns from PageC to PageB.
Upvotes: 1