view - 为什么 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 任何输入表示赞赏。
解决方案
似乎根据上下文分配了不同的解决方案,对我来说,解决方案是将加载程序创建调用从模块构造函数移动到调用存在和关闭的方法:
tryGeolocation() {...
this.loading = this.loadingCtrl.create();
this.loading.present();
//some code
this.loading.dismiss();
}
推荐阅读
- python - 在熊猫数据框中订购一列
- javascript - 通过javascript杀死或崩溃chrome中的进程
- kubernetes - Kubernetes 中“minikube 插件列表”的等效命令是什么?
- json - 无法在我的 RN 项目中使用打字稿“useEffect”获取本地 json
- pandas - Edgelist Pandas:获取列中两个组合之间的共同值的数量
- python - 是否有一个公式可以在 Python 中为分辨率创建通用坐标?
- r - RDA 和超参数随机搜索的过度拟合结果?
- r - 在R中更改日期和时间格式的问题
- azure-devops - 条件表达式在 Azure DevOps 2019 中不起作用
- node.js - 这是nodejs上的内存泄漏吗?