我试图在Ionic 2中使用提示警报内的基本警报时被困住了

时间:2017-08-22 15:14:52

标签: ionic2 alert

我的问题v.simple但我无法找到解决方案。我尝试在提示警报内显示基本警报以显示我输入的结果,但我不知道我的申请卡住的原因。

这是我的代码的基本示例,并且当#34;重复的电子邮件"警报显示,当我点击确定按钮

时我无法关闭它
let prompt = this.alertCtrl.create({
title: 'Replacement Email',
message: "Please enter your new email",
inputs: [{
    type: 'email',
name: 'email',
placeholder: 'user1@gmail.com'
},
],
buttons: [
  {
    text: 'Cancel',
    handler: data => {
      console.log('Cancel clicked');
    }
  },{
    text: 'Save',
    handler: data => { 
      if(data.email!=""){
        if(data.email==this.userService.email){
           let alert = this.alertCtrl.create({
              title: "Duplicated email",
              subTitle: "Please enter new email",
              buttons: ['OK']
            });
            alert.present();
         }
      }
    }
  }
]
});
prompt.present();

1 个答案:

答案 0 :(得分:0)

我通过使用" timeout"解决了这个问题。但我认为这个问题有更好的解决方案

let prompt = this.alertCtrl.create({
title: 'Replacement Email',
message: "Please enter your new email",
inputs: [{
    type: 'email',
name: 'email',
placeholder: 'user1@gmail.com'
},
],
buttons: [
  {
    text: 'Cancel',
    handler: data => {
      console.log('Cancel clicked');
    }
  },{
    text: 'Save',
    handler: data => { 
      if(data.email!=""){
        if(data.email==this.userService.email){
           let alert = this.alertCtrl.create({
              title: "Duplicated email",
              subTitle: "Please enter new email",
              buttons: ['OK']
            });
            setTimeout(() => {
                alert.present();
            },250);
         }
      }
    }
  }
]
});
prompt.present();