【问题标题】:Ionic 4 Loading Controller continues after dismissingIonic 4 Loading Controller 关闭后继续
【发布时间】:2019-06-26 13:20:16
【问题描述】:

我正在使用 Ionic 4 和加载控制器。

async presentLoading() {
    const loading = await this.loadingCtrl.create({
      message: 'wait. . .'
    });
    return await loading.present();
}

效果很好。但现在我想以编程方式关闭加载程序。

this.loadingCtrl.dismiss().then(a => console.log('dismissed'));

即使我在控制台上看到“已关闭”(日志记录有效),加载覆盖仍在继续。知道可能是什么原因吗?

【问题讨论】:

    标签: ionic-framework ionic4


    【解决方案1】:

    您不会关闭显示的实际加载程序。您必须使用 loading 变量将其关闭,如下所示:

    loading.dismiss().then(a => console.log('dismissed'));
    

    请注意,我使用了您为当前加载程序声明的变量 loading

    【讨论】:

      【解决方案2】:
       If you want to dismiss programmatically use this in your service. 
      
      
      
      export class LoaderService {
       private isLoading = false;
       constructor(private loadingController: LoadingController) {
        }
      
        async presentLoading() {
          // issue generated! so we used Boolean value to set loader dismissed call 
               firstly so we used this logic
          this.isLoading = true;
          let loading = await this.loadingController.create({
          message: 'Please Wait',
          spinner: 'bubbles'
        }).then((res) => {
            res.present();
            if (!this.isLoading) {
              // res.dismiss().then(()=> console.log('abort presenting'));
              this.loadingController.dismiss().then(() => 
      console.log('Dismissed'));
           }
          });
          return loading;
        }
      

      异步 ​​hideLoading() { this.isLoading = false; return await this.loadingController.dismiss().then(() => console.log('Dismissed')); } }

      【讨论】:

      • 不起作用.. 不知道为什么 ionci 添加了基于异步和承诺的加载器everyehwere
      猜你喜欢
      • 1970-01-01
      • 2011-10-28
      • 2013-04-24
      • 2015-08-17
      • 2018-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多