Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic - Error: Uncaught (in promise): removeView was not found

My Ionic app was working fine and I haven't done anything to it but suddenly I am getting this error and I don't know why.

"Error: Uncaught (in promise): removeView was not found

like image 256
Samir Boulos Avatar asked May 07 '17 06:05

Samir Boulos


4 Answers

Deleting a component is not a solution to any problem.

Cause of issue: There are multiple calls to dismiss method of loading component.

Solution: While creating the loader, check if the loader instance is not already present, only then create another instance.

Similarly, while dismissing the loader, check if the loader instance does exists, only then dismiss it.

Code:

constructor(private _loadingCtrl: LoadingController){}

loading;

showLoading() {
    if(!this.loading){
        this.loading = this._loadingCtrl.create({
            content: 'Please Wait...'
        });
        this.loading.present();
    }
}

dismissLoading(){
    if(this.loading){
        this.loading.dismiss();
        this.loading = null;
    }
}
like image 116
Manoj Negi Avatar answered Nov 09 '22 03:11

Manoj Negi


When you want to manually dismiss the Ionic loading you may need to follow the below example. Which is working fine I have tested in ionic labs.

Ionic 3+

Note: If you call this.loading.dismiss() manually, I don't recommend to use dismissOnPageChange, you are probably dismissing the same loading twice.

Why the below solution works?

I think this.loading.present() is an asynchronous method, so we can't call this.loading.dismiss() manually when this.loading.present() is still running.

So if we need to dismiss manually we need to make sure that loading is present already and have a view to dismiss it, we should use other method after present().then like the following code.

However I'm not sure why we didn't have this problem in the old framework version (2.0.3).

import { Loading, LoadingController } from 'ionic-angular';

export class ApnSearchPage {
   loading: Loading;
   constructor(private loadingCtrl: LoadingController) { }

   ionViewDidLoad() {
     this.createLoader();
   }

   createLoader(message: string = "Please wait...") { // Optional Parameter
     this.loading = this.loadingCtrl.create({
       content: message
     });
   }

   public searchClick() {
       this.createLoader();
       this.loading.present().then(() => {
       this.searchService.submitRequest(params, data)
            .subscribe(response => {
                this.loading.dismiss();
            }, error => {
              this.loading.dismiss();
              this.errorMessage = <any>error
            });
      });
   }
}

Reference Link,hence posted only useful and working tips and code.

I hope this helps!

like image 44
RajeshKdev Avatar answered Nov 09 '22 01:11

RajeshKdev


For me, the problem was that I had

dismissOnPageChange: true

when I created the loadingCtrl.

The .dismiss() was being called too soon after the .present() (during local testing the api responds really fast) and it seems having that parameter caused the issue. Removing it solved it for me.

like image 1
jeudyx Avatar answered Nov 09 '22 02:11

jeudyx


For me, the simple fix was changing:

this.loader.dismiss()

to:

this.loader.dismiss().then(value => {
    console.log("dismiss worked!");
}, reason => {
    console.log("dismiss rejected!");
});
like image 1
Peter Avatar answered Nov 09 '22 02:11

Peter