首页 > 解决方案 > 为什么 Ionic 3 离子加载器会抛出 removeView 错误/在解除/存在检查到位时不显示

问题描述

我正在使用一个离子加载组件,它在第一次访问视图并且加载器被呈现和关闭时工作正常。

import { AlertController, LoadingController } from 'ionic-angular';
constructor(
    public zone: NgZone,
    public loadingCtrl: LoadingController,
    public alertCtrl: AlertController,
    private storage: Storage,
    public navCtrl: NavController
  ) {
this.loading = this.loadingCtrl.create();
}

tryGeolocation() {
this.loading.present();
//misc code
 this.markers.push(marker);
      this.map.setCenter(pos);
      //if(this.loading){
      this.loading.dismiss();
}

但是,当我导航回视图并再次显示加载程序时,出现错误:

错误:未捕获(承诺):未找到 removeView

我尝试遵循此处的建议并引入检查以查看加载程序是否已被解雇,但现在加载程序从未出现:

if (this.loading == null){
          console.log("Map.ts: Presenting loader.");
          this.loading.present();
        }
    if (this.loading != null){
          console.log("Map.ts: Dismissing loader.");
          this.loading.dismiss();
        }

我正在使用 ionic 3.9.9,angular 5.2.11 任何输入表示赞赏。

标签: viewionic3loader

解决方案


似乎根据上下文分配了不同的解决方案,对我来说,解决方案是将加载程序创建调用从模块构造函数移动到调用存在和关闭的方法:

tryGeolocation() {...
     this.loading = this.loadingCtrl.create();
     this.loading.present();
     //some code
     this.loading.dismiss();   
}

推荐阅读