【问题标题】:Uncaught (in promise): inserted view was already destroyed?未捕获(承诺):插入的视图已被破坏?
【发布时间】:2017-11-19 22:56:56
【问题描述】:

我在主页上使用加载器,并在我点击 API 以检查用户详细信息时显示它,并在 API 响应我时将其关闭。当我输入正确的电子邮件和密码时,它工作正常。但是当我填写不正确的电子邮件和密码时,它可以工作,但是下次当我输入正确或不正确的电子邮件 ID 和密码时,它会显示一个错误“未捕获(承诺):插入的视图已被破坏”。如何修复它。我已经应用了以下链接Ionic - Error: Uncaught (in promise): removeView was not found 中给出的建议。但这对我不起作用。 我的代码如下所示

import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NavController, AlertController, ToastController, ViewController, Events, LoadingController } from 'ionic-angular';
import { WelcomePage } from '../welcome/welcome';
import { PmsServiceProvider } from '../../providers/pms-service/pms-service';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  public emailError: boolean = false;
  public passwordError: boolean = false;
  userForm: FormGroup;
  public loginStatus: boolean = true;
  public rememberChecked = true;
  Email;
  Password3;
  check;
  logined : boolean =false;
  checkStatus=1;

   toast = this.toastCtrl.create({
  message: 'Please enter correct email Id and password',
  duration: 3000,
  position: 'bottom'
})

public loading = this.loadingCtrl.create({
  content: 'Loading...',
  spinner: 'bubbles'
});

  constructor(public navCtrl: NavController, private form: FormBuilder, private alertCtrl: AlertController, private toastCtrl: ToastController, private service: PmsServiceProvider, public viewCtrl : ViewController, public events: Events,  public loadingCtrl: LoadingController) {
       console.log("in constructor");
       events.subscribe('user:created', (data)=>{
            this.Email=localStorage.getItem("email");
            this.Password3=localStorage.getItem("password");
       })
    this.userForm = form.group({
      email: [null, [Validators.required]],
      password: [null, [Validators.required]]
    })
  }    

  login(inputForm) {
       console.log(inputForm.value.email);
       console.log(inputForm.value.password);
    if (inputForm.value.email == null || inputForm.value.email == "") {
      this.emailError = true;
    } else {
      this.emailError = false;
    }

    if (inputForm.value.password == null || inputForm.value.password == "") {
      this.passwordError = true;
    } else {
      this.passwordError = false;
    }

    if (inputForm.value.email == null || inputForm.value.password == null || inputForm.value.email == "" || inputForm.value.password == "") {
         console.log("one is null");
      this.loginStatus = false;
    }
    else {
      this.loginStatus = true;
    }

    //CODE FOR TESTING THE EMAIL ID AND PASSWORD IS CORRECT 
    // Hit to the Api.
    if (this.loginStatus == true) {
           this.loading.present().then(()=>{
                this.service.checkUser(inputForm.value).subscribe(resData => {
                    //  console.log(resData.data.body);
                    console.log(resData);
                    if(this.loading){
                         this.loading.dismiss();
                         // this.loading =null;
                    }

                    //  console.log(resData.success);
                    //  console.log(resData.body[0]);
                  if (resData.success == true) {
                       if(this.rememberChecked ==true){
                            localStorage.setItem("email",inputForm.value.email);
                            localStorage.setItem("password",inputForm.value.password);
                            localStorage.setItem("user_id",resData.data.body[0].id);
                       }else{
                            localStorage.setItem("email","");
                            localStorage.setItem("password","");
                       }
                    // console.log(resData.respData[0].id);
                    localStorage.setItem("token",resData.data.mytoken);
                    console.log(resData.data.body[0].first_name);

                    this.navCtrl.push(WelcomePage, { id: resData.data.body[0].id, name : resData.data.body[0].first_name}).then(()=>{
                         const index = this.navCtrl.getActive().index;
                         this.navCtrl.remove(0,index);
                    });
                    // this.navCtrl.setRoot(WelcomePage);
                  }
                  else {
                    this.toast.present();;
                  }
                })
           });
     ;
    }
  }

}

请帮帮我。

【问题讨论】:

标签: javascript ionic-framework ionic2 ionic3


【解决方案1】:

您需要在每次需要时为 LoadingController 创建新对象。 公共加载:任何

constructor(private loadingCtrl: LoadingController){}

presentLoadingDefault() {
    this.loading= this.loadingCtrl.create({
      content: 'Please wait...'
    })

    this.loading.present()
}

当你想显示加载器或微调器时,你应该调用这个方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 2023-02-06
    • 2021-11-15
    • 2016-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多