如何在离子2上单击其外部时不关闭警报框

时间:2017-06-22 21:30:25

标签: angular typescript ionic-framework ionic2 ionic3

我正在构建一个离子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();
  }
}

如何确保当我在框外点击警报时不会被解雇?

3 个答案:

答案 0 :(得分:35)

正如您在the AlertController docs中所看到的,您可以在创建警报时使用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();
  }
}

答案 1 :(得分:4)

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

backdropDismiss: false

答案 2 :(得分:1)

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