ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Loading component is not working inside Modal Page.

Open srishiva89 opened this issue 10 years ago • 8 comments

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..

srishiva89 avatar Aug 24 '16 03:08 srishiva89

Hello! Would you mind sharing a repo or code snippet i can use to reproduce this issue? Thanks for using Ionic!

jgw96 avatar Aug 24 '16 04:08 jgw96

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>

srishiva89 avatar Aug 25 '16 13:08 srishiva89

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!

jgw96 avatar Aug 25 '16 16:08 jgw96

I already added loading.present() in my code. I forget to mention in above code snippet.

srishiva89 avatar Aug 25 '16 16:08 srishiva89

Are you presenting the loading component in an ionic lifecycle event or in OnInit?

jgw96 avatar Aug 25 '16 16:08 jgw96

I used it in ngOnInitmethod.

srishiva89 avatar Aug 25 '16 17:08 srishiva89

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!

jgw96 avatar Aug 25 '16 18:08 jgw96

Great thanks to you.. It is working perfectly.....

srishiva89 avatar Aug 26 '16 13:08 srishiva89