我在主页上使用加载程序,并在我点击 API 来检查用户详细信息时显示它,并在 API 响应我时关闭它。当我输入正确的电子邮件和密码时,它工作正常。但是,当我填写了不正确的电子邮件和密码时,它可以工作,但下次当我输入正确或不正确的电子邮件 ID 和密码时,它会显示错误“未捕获( promise ):插入的 View 已被破坏”。如何修复它。我已经应用了以下链接 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 创建新对象。 公共(public)加载:任意
constructor(private loadingCtrl: LoadingController){}
presentLoadingDefault() {
this.loading= this.loadingCtrl.create({
content: 'Please wait...'
})
this.loading.present()
}
当你想显示加载器或微调器时,应该调用此方法
关于javascript - 未捕获( promise ): inserted view was already destroyed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44601531/