gpt4 book ai didi

angular - 在 Ionic 上单击警告框外部时如何不关闭警告框

转载 作者:太空狗 更新时间:2023-10-29 16:54:47 32 4
gpt4 key购买 nike

我正在构建一个 ionic 2 应用程序,我正在使用以下组件

http://ionicframework.com/docs/components/#alert

  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']
});
alert.present();
}
}

如何确保当我在框外单击时不会关闭警报?

最佳答案

ionic 2/3:

正如您在 the AlertController docs 中看到的那样,您可以在创建警报时使用 enableBackdropDismiss( bool 值)选项:

enableBackdropDismiss: Whether the alert should be dismissed by tapping the backdrop. Defaulttrue

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();
}
}

ionic 4/5:

在 ionic 4/5 this property已重命名为 backdropDismiss:

backdropDismiss: If true, the alert will be dismissed when the backdrop is clicked.

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();
}
}

关于angular - 在 Ionic 上单击警告框外部时如何不关闭警告框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44709702/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com