Loading component is not working inside Modal Page.
In my page, I've a search button. If i click that search button, I'm showing up one modal (Modal Component) page and displaying data which are retrieved from an API. But it took some time to display data from an API. So I tried to use Loading component in Modal page. But it is not working as I expected.
I've already used one loading component in my root page. It is working.
The issue is loading component is not working in Modal page..
Hello! Would you mind sharing a repo or code snippet i can use to reproduce this issue? Thanks for using Ionic!
Code snippet:
I have used ModalPage in same MyPage.ts file. I mean I didn't create new ts file for Modal Page.
MyPage.ts
export class MyPage implements OnInit{
public openModal(): any{
let modal Modal = this,modalCtrl.create(ModalPage, this.myParam);
}
}
export class ModalPage implements OnInit{
let loading: Loading = this.loadingController.create({
content: 'Loading..',
});
setTimeout(
() => {
loading.dismiss();
},
4000
);
}
MyPage.html:
<ion-buttons end>
<button (click)="openModal()">
<ion-icon name="search"></ion-icon>
</button>
</ion-buttons>
Hmm, from looking at your code sample above it does not look like you are presenting the modal. Would you try this please?
let loading = this.loadingCtrl.create({
content: 'Loading...'
});
loading.present()
Thanks for using Ionic!
I already added loading.present() in my code. I forget to mention in above code snippet.
Are you presenting the loading component in an ionic lifecycle event or in OnInit?
I used it in ngOnInitmethod.
Ahh that is the issue. The ngOnInit angular lifecycle event actually fires way before the ui of the component is loaded and ready to go. Because of this you cannot do ui related things such as opening a loading component in ngOnInit. We recommend using our lifecycle events in Ionic 2 apps. Specifically, for anything ui related you would want to put the logic in the ionViewDidEnter event. Thanks for using Ionic!
Great thanks to you.. It is working perfectly.....