离子 2/3:
正如您在AlertController 文档中看到的那样,您可以enableBackdropDismiss
在创建警报时使用 (boolean) 选项:
enableBackdropDismiss:是否应该通过点击背景来解除警报。默认为真
import { AlertController } from 'ionic-angular';
// ...
export class MyPage {
constructor(public alertCtrl: AlertController) {}
showAlert() {
let alert = this.alertCtrl.create({
title: 'New Friend!',
subTitle: 'Your friend, Obi wan Kenobi, just accepted your friend request!',
buttons: ['OK'],
enableBackdropDismiss: false // <- Here! :)
});
alert.present();
}
}
离子 4/5:
在 Ionic 4/5中,此属性已重命名为backdropDismiss
:
backgroundDismiss :如果为 true,则单击背景时将关闭警报。
import { AlertController } from '@ionic/angular';
//...
export class MyPage {
constructor(public alertController: AlertController) {}
async showAlert() {
const alert = await this.alertController.create({
header: 'Alert',
subHeader: 'Subtitle',
message: 'This is an alert message.',
buttons: ['OK'],
backdropDismiss: false // <- Here! :)
});
await alert.present();
}
}