28

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

Samir Boulos
  • 423
  • 1
  • 6
  • 14

11 Answers11

55

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;
    }
}
Manoj Negi
  • 947
  • 12
  • 13
  • I am using two types of controller.. one is loading controller and the other one is AlertController, i tried this code but it still throws an error "removeView was not found".. What can be the problem??? – fiza khan Apr 23 '18 at 11:16
  • I enhanced it to include pseudo reference counting to not remove throbber early if multiple operations are requesting it – zakius Aug 29 '18 at 00:58
  • do we need to use the "create()" inside every pages we make in ionic? Can't we make a global provider and just make two function like show() and hide()? – Kunal Kakkad Nov 21 '18 at 06:58
44

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!

RajeshKdev
  • 6,029
  • 6
  • 53
  • 76
  • But it still throws error "removeView was not found".. i am also using the confirm prompt.. is that causing error??? – fiza khan Apr 23 '18 at 11:15
1

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.

jeudyx
  • 659
  • 1
  • 8
  • 16
1

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!");
});
Peter
  • 983
  • 2
  • 12
  • 15
0

I managed to solve it by deleting the LoadingController from my component.

Samir Boulos
  • 423
  • 1
  • 6
  • 14
0

I removed loading.dismiss function and solved it.

chii
  • 1,377
  • 11
  • 18
0

it says that you called to loading.dismiss() before load.presenet() ended. you should try

let a = this.loadingCtrl.create({content : 'hello world'})
await a.present();
..
.. // your code goes here..
...
a.dismiss()
0

Here is one for the alertController but works very similar.

logout() {
  let prompt = this.alertCtrl.create({
    title: 'Logout',
    subTitle: 'Are You Sure You Want To Logout?',
    buttons: [
      {
        text: 'No',
        handler: data => {
          let navTransition = prompt.dismiss();
           navTransition.then(() => {
             this.navCtrl.pop();
           });
         return false;
       }

     },
     {
       text: 'Yes',
       handler: data => {
         this.lgout();
       }
     }
   ]
  });
 prompt.present();
}
0

Here is my simplest solution to this problem:

I have got this problems when implementing the LoadingController

Note: Don't initialize loader inside the construction (it works only first time and from second time you will get stuck with remove view not found problem)

loading:any;

this.loading=this.loadingCtrl.create({
        spinner:'bubbles',
        content:`Please wait..`
      });

I was displaying the loader while getting data from server Below is the working code

 gosignup(number:string){

    this.loading.present();//showing the loader
    //calling webservice 
    this.Authprovider.smsverify(number).subscribe(
      data=>{                  
        this.loading.dismiss();//to dismiss loader        
        if(data.json().msg=="success"){
           this.navCtrl.push(SignupPage,{
             user:this.Usersignup
           })
        }

        if(data.json().msg=="error"){
          this.showToastWithCloseButton("Invalid otp");
        }

      },

      err=>{
          this.loading.dismiss();
          this.showToast("Please try again later");
      },

      ()=>{
              this.loading.dismiss();//to dismiss loader
      }

      );



  }

Hope it will solve SO problems

Suraj Bahadur
  • 2,901
  • 3
  • 18
  • 42
0

Please try the below which worked for me

import { App } from 'ionic-angular';
export class PopoverPage {
   constructor(public navCtrl: NavController
     , public viewCtrl: ViewController
    , public appCtrl: App) {
         this.viewCtrl.dismiss().then(()=>{
          setTimeout(()=>{
            confirm.dismiss().then(()=>{
              this.appCtrl.getRootNav().setRoot('DashboardPage');
            })
          },300)
        })
    }
 }
puneet
  • 116
  • 1
  • 2
0

I updated to the latest version @ionic/app-scripts 3.3.0 and this is also happening in my app.

MD.Riyaz
  • 392
  • 2
  • 8