我正在使用主页上的加载程序,并在单击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();;
                  }
                })
           });
     ;
    }
  }

}


请帮帮我。

最佳答案

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

constructor(private loadingCtrl: LoadingController){}

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

    this.loading.present()
}


要显示加载程序或微调器时,应调用此方法

09-11 19:15