2

I am calling two api call in single page. but if i use one api call its working fine. But if i use two api call in same page. I'm getting below error at Runtime.

Error Uncaught (in promise): removeView was not found`.

And i have one doubt too. Where ever i go to any screens. If i want to come back to my home screen. I need to show the Api called Data to display always. So should i need to call my Api call method inside constructor or ionViewDidEnter. i did in ionViewDidEnter i don't things show this may be the causes for my error.

Here is my code :

import { Component, ViewChild } from '@angular/core';
import { AlertController, App, FabContainer, ItemSliding, List, ModalController, NavController, ToastController, LoadingController, Refresher } from 'ionic-angular';
import { CategoryDetailPage } from '../categorydetail/categorydetail';
import { ConferenceData } from '../../providers/conference-data';
import { UserData } from '../../providers/user-data';
import { SessionDetailPage } from '../session-detail/session-detail';
import { ScheduleFilterPage } from '../schedule-filter/schedule-filter';
import {Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import { AuthService } from '../../providers/AuthService';

@Component({
  selector: 'page-speaker-list',
  templateUrl: 'speaker-list.html'
})

export class SpeakerListPage {
   loading: any;
   data: any;
   Catdata: any;
   Catdatanames: any;
   resdata: any;
   resCatdata: any;
   resCatdatanames: any;
   loginData: {username?: string} = {};
   resloginData: {username?: string} = {};

  constructor(
    public alertCtrl: AlertController,
    public app: App,
    public loadingCtrl: LoadingController,
    public modalCtrl: ModalController,
    public navCtrl: NavController,
    public toastCtrl: ToastController,
    public confData: ConferenceData,
    public user: UserData,
    public http:Http,
    public authService: AuthService) { }

  ionViewDidEnter() {
   this.show();
   this.another();
  }

  show() {
    this.showLoader();
      this.authService.subs(this.loginData).then((result) => {
      this.loading.dismiss();
      this.data = result;

       if(this.data.status == 1)
       {
           this.Catdata = this.data.SubjectList;
           for(let i=0; i<this.Catdata.length; i++) {
               console.log(this.Catdata[i].SubjectName);
           }
       }
       else if(this.data.status == 0) {
          let alert = this.alertCtrl.create({
              title: 'Error',
              subTitle: 'Please Enter Valid Username & Password',
              buttons: ['OK']
          });
          alert.present();
       }
    }, (err) => {
      this.loading.dismiss();
    });
}

another() {
  this.showLoader();
    this.authService.allresources(this.resloginData).then((result) => {
      this.loading.dismiss();
      this.resdata = result;

      if(this.resdata.status == 1)
      {
           this.resCatdata = this.resdata.SubjectList;
           for(let i=0; i<this.resCatdata.length; i++) {
               console.log(this.resCatdata[i].FileName);
           }
      }
      else if(this.resdata.status == 0) {
         let alert = this.alertCtrl.create({
            title: 'Error',
            subTitle: 'Please Enter Valid Username & Password',
            buttons: ['OK']
         });
         alert.present();
       }
    }, (err) => {
      this.loading.dismiss();
    });
}

showLoader(){
    this.loading = this.loadingCtrl.create({
        content: 'Authenticating...'
    });
    this.loading.present();
  }
}

Please help me out. How can solve my issue?

My ionic info:

Cordova CLI: 6.5.0 
Ionic Framework Version: 3.1.1
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.3.5
ios-deploy version: 1.9.0 
ios-sim version: 5.0.13 
OS: macOS Sierra
Node Version: v7.3.0
Xcode version: Xcode 8.3.2 Build version 8E2002

Help will be much useful.Thanks

RajeshKdev
  • 6,365
  • 6
  • 58
  • 80
venky
  • 139
  • 4
  • 12
  • if you are using loading then try to comment it on this page and try with two get calls itself – Mohan Gopi May 06 '17 at 07:17
  • @MohanGopi sorry i din get you.i am ew to ionic. can u explain me what should i do – venky May 06 '17 at 07:19
  • you are using `this.loading.present();` and`this.loading.dissmiss()` in your Api call comment that part and try – Mohan Gopi May 06 '17 at 07:21
  • oh i need to comment the loading part. Okay.will try. but when i want the data to show whenever i come this screen. should i need to call that two method inside constructor or under `ionViewDidEnter` – venky May 06 '17 at 07:21
  • it depends upon your requirement – Mohan Gopi May 06 '17 at 07:23
  • requirement ??. not like that for me. if i some screens. and again if i come that home screen. i need the api called and the data have to diaplay always. so should i need to put under constructor or `ionViewDidEnter` – venky May 06 '17 at 07:25
  • @MohanGopi now i am getting new error `TypeError: Cannot read property 'length' of undefined `.. under my api call method. – venky May 06 '17 at 07:28
  • did your check your api call in post man i think `this.Catdata.length;` is error check in post man what do you get and check the Catdata array is correctly assigned or not – Mohan Gopi May 06 '17 at 07:30
  • `this.Catdata.length ` no parameters like length. ist the for loop that i got solution from stack overflow. here that solution given like http://stackoverflow.com/questions/43800137/how-to-call-object-value-ionic-2 – venky May 06 '17 at 07:31
  • make your api calls in constructor itself after navigating to next and returning back is not able do the api call the move the api call in ionviewdidenter – Mohan Gopi May 06 '17 at 07:32
  • ok check it in postman and let me know – Mohan Gopi May 06 '17 at 07:33
  • i have checked. only ` "CatID": "13", "CategoryName": "Plant Physiology", "CategoryStatus": "Active"` is available like 10 datas – venky May 06 '17 at 07:35
  • @MohanGopi i din get you about the `make your api calls in constructor itself after navigating to next and returning back is not able do the api call the move the api call in ionviewdidenter` this message. ........ after navigating to next pages adn returing to home pages will not call the api call. So its better to do that api call method under `constructor` . let me know if i got your point correctly ?? – venky May 06 '17 at 07:36
  • ok tell me one thing if you navigate to another page and come back to the previous page what you are getting – Mohan Gopi May 06 '17 at 07:37
  • some times its showing the data some times not if i put in constructor or under `ionviewdidload` i tried. thast why asked which one is need to do under constructor or `ionviewdidload` or `ionViewDidEnter` – venky May 06 '17 at 07:39
  • And that length error i am getting . and there is one test close at top `run time error`. if i press close . my data are showing in screen. but i dont know why i am getting that error when i run – venky May 06 '17 at 07:40
  • `ionViewDidEnter` will always all the api when ever you vist the page – Mohan Gopi May 06 '17 at 07:43
  • thanks, now what should i need to do for my length error. any solution please – venky May 06 '17 at 07:45
  • comment the show() funtion and then check if you are ok the comment the another() function and check that will let you know which is making the error – Mohan Gopi May 06 '17 at 07:50
  • @MohanGopi you are right in my `another()` its making the issue.i also posted my `another()` method api call json data output from my db. what ia m wrong really not able to identify – venky May 06 '17 at 08:04
  • ask new question related to your error so that you will get a clear answer – Mohan Gopi May 06 '17 at 08:13
  • @MohanGopi can u help me here : http://stackoverflow.com/questions/43819687/data-are-not-showing-when-two-api-called-in-iondidenter – venky May 06 '17 at 11:41
  • 1
    did you manage to solve the "Uncaught (in promise): removeView was not found" error? I am having the same and I don't know how to resolve. – Samir Boulos May 07 '17 at 07:51
  • @SamirBoulos if you have two methods or two api call methods. And if you use some loading controller or any loader . Try to make it as one loader for all method calling – venky May 07 '17 at 08:30
  • Want to note that this happened to me with dismissOnPageChange and a manual dismiss. – misha130 May 09 '17 at 18:29

4 Answers4

1

I know this question asked more than a month ago!

I was going through the same scenario with same problem and i sorted out this issue.

And i have posted the answer in another stackoverflow Question.

Some of the discussion and reference available to get know the issue.

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

I think this.loading.present() is 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 presented and have a view to dismiss it, we should use other method after present().then like my code in below.

    public searchClick() {
       this.createLoader();
       this.loading.present().then(() => {
       this.searchService.submitRequest(params, data)
            .subscribe(response => {
                this.loading.dismiss(); // Dismissing the loader manually.
                //Call the other function
                //You can dismiss loader here 
                //You can dismiss loader in other functions too by calling it from here, Since the scope will be available to that also.
            }, error => {
              this.loading.dismiss();
              this.errorMessage = <any>error
            });
      });
   }

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

I hope this helps you out/gives you idea about your problem, if you still have the issue.

Ionic Framework LoadingController Documentation for this.

RajeshKdev
  • 6,365
  • 6
  • 58
  • 80
1

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 Singh
  • 1,911
  • 1
  • 20
  • 22
0

I solved the following by using this method.

this.loading.dismissAll();
Jonatas Rodrigues
  • 57
  • 1
  • 2
  • 12
0

I had the same error which was caused by accidentally having two handlers firing. One was part of the form as an ngSubmit attribute, the other one was on a custom save button. Removing one of the two solved it.

mvandillen
  • 904
  • 10
  • 17