[英]Ionic 3 LoadingController removeView was not found
我正在制作一個離子3應用程序,並希望在每個導航上添加一個加載微調器。 所以我創建了一個loadingService並將其添加到我的navigationService中,以便自動處理所有導航。
為了啟動和停止我使用的加載器:
export class LoaderService{
loading: Loading;
constructor(public loadingCtrl: LoadingController ){
this.loading = this.loadingCtrl.create({
spinner: 'crescent'
})
}
startLoader(){
this.loading.present();
}
stopLoader(){
this.loading.dismiss();
}
}
第一次導航后我得到錯誤
錯誤錯誤:未捕獲(在承諾中):已插入的視圖已被銷毀
錯誤錯誤:未捕獲(在承諾中):找不到removeView
問題是this.loading.dismiss()
加載器實例沒有被正確解除,因此在啟動新加載器之前你需要做的是:
this.loading.dismissAll();
this.loading = null;
所以我改變了我的服務(這可能會更好,但你會得到這個想法)。
export class LoaderService{
loading: Loading;
constructor(public loadingCtrl: LoadingController ){
}
startLoader(){
this.loader();
return this.loading.present();
}
stopLoader(){
this.loading.dismissAll();
this.loading = null;
}
private loader(){
if(this.loading && this.loading.instance){
this.stopLoader();
}
this.loading = this.loadingCtrl.create({
spinner: 'crescent',
dismissOnPageChange: true,
})
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.