typescript 在 Ionic 上单击警报框外部时如何不关闭警报框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44709702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:39:44  来源:igfitidea点击:

How to not dismiss the alert box when clicking outside of it on Ionic

angulartypescriptionic2ionic3ionic4

提问by hopper

I am building a ionic 2 app and I am using the following component

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

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

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

How can I make sure that when I click outside the box the alert is not dismissed?

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

回答by sebaferreras

Ionic 2/3:

离子 2/3:

As you can see in the AlertController docs, you can use the enableBackdropDismiss(boolean) option when creating the alert:

正如您在AlertController 文档中看到,您可以enableBackdropDismiss在创建警报时使用(boolean) 选项:

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

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

Ionic 4:

离子4:

In Ionic 4 this propertyhas been renamed to backdropDismiss:

在 Ionic 4 中,此属性已重命名为backdropDismiss

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

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

回答by Pete

In ionic 4 the option has been renamed to

在 ionic 4 中,该选项已重命名为

backdropDismiss: false

回答by amuramoto

Set enableBackdropDismiss: false in the alertCtrl.create options

在 alertCtrl.create 选项中设置 enableBackdropDismiss: false