ionic2的弹框注意细节
在需要弹框的场景中,如果根据用户对弹框的选择需要在其交互之后再一次弹框,必须在上一次弹框的逻辑里把弹框先dismiss掉,然后在onDidDismiss的方法里编写下一个弹框,这样才能流畅(不卡死或闪屏)的切换弹框
constructor(private alertCtrl: AlertController) {
}
presentAlert() {
let alerlOne = this.alertCtrl.create({
title: 'text1',
subTitle: 'text2',
buttons: ['Dismiss']
});
alert.present();
}
presentConfirm() {
let alertTwo = this.alertCtrl.create({
title: 'Confirm purchase',
message: 'Do you want to buy this book?',
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
}
},
{
text: 'Buy',
handler: () => {
alertTwo.dismiss();
alertTwo.onDidDismiss(() => {
this.presentAlert();
})
}
}
]
});
alert.present();
}