简体   繁体   English

Ionic 3 LoadingController找不到removeView

[英]Ionic 3 LoadingController removeView was not found

I am making an ionic 3 app and wanted to add a loading spinner on every navigation. 我正在制作一个离子3应用程序,并希望在每个导航上添加一个加载微调器。 So I created a loadingService and added it to my navigationService in order to handle all navigations automatically. 所以我创建了一个loadingService并将其添加到我的navigationService中,以便自动处理所有导航。

In order to start and stop loader I used: 为了启动和停止我使用的加载器:

export class LoaderService{
    loading: Loading;
    constructor(public loadingCtrl: LoadingController ){
        this.loading = this.loadingCtrl.create({
            spinner: 'crescent'
        })
    }

    startLoader(){
        this.loading.present();
    }

    stopLoader(){
        this.loading.dismiss();
    }
}

After the first navigation I get errors 第一次导航后我得到错误

ERROR Error: Uncaught (in promise): inserted view was already destroyed 错误错误:未捕获(在承诺中):已插入的视图已被销毁

ERROR Error: Uncaught (in promise): removeView was not found 错误错误:未捕获(在承诺中):找不到removeView

The issue was that with this.loading.dismiss() loader instance are not dismissed correctly, so what you have to do before starting a new loader is: 问题是this.loading.dismiss()加载器实例没有被正确解除,因此在启动新加载器之前你需要做的是:

this.loading.dismissAll();
this.loading = null;

So I altered my service like this (this can be better but you'll get the idea). 所以我改变了我的服务(这可能会更好,但你会得到这个想法)。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM