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

前端 未结 20 2243
逝去的感伤
逝去的感伤 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:30

    I know this question is to ask about a year ago. I facing the same problem. I just want to post my solution. I hope the upcoming visitor will get help.

    async dismissLoading() {
        console.log("dismiss");
        this.isLoading = false;
      }
     private async presentLoading(msg) {
        console.log("loading");
        const loading = await this.loadingCtrl.create({
          message: msg,
        });
        await loading.present();
        var timer = setInterval(() => {
          if (!this.isLoading) {
            loading.dismiss();
            clearInterval(timer);
            console.log("set dismiss");
          }
        }, 1000);
      }
      async loadingmsg() {
        this.isLoading = true;
        await this.presentLoading("Please wait while...");
      }

    this solution work for me. Please correct me if I am wrong.

提交回复
热议问题