Ionic 4: “Loading Controller” dismiss() is called before present() which will keep spinner without dismissing

前端 未结 20 2290
逝去的感伤
逝去的感伤 2020-12-08 01:06

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

20条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 01:44

    I found a new way to do this. I hope it help! It’s using the id of loading. So if you have many loadings you don’t want to dismiss wrong loading.

    In the service:

    async showLoading(loadingId: string, loadingMessage: string = 'Loading...') {
                const loading = await this.loadingCtrl.create({
                  id: loadingId,
                  message: loadingMessage,
                  spinner: 'circles'
                });
                return await loading.present();
    }
    
    async dismissLoader(loadingId: string) {
      return await this.loadingCtrl.dismiss(null, null, loadingId).then(() => console.log('loading dismissed'));
    }
    

    In the component calling the loading:

    await this.globalVars.showLoading('ifOfLoading')
    

    Dismissing the loading:

    this.globalVars.dismissLoader('ifOfLoading')
    

提交回复
热议问题