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

问题描述 投票:13回答:3

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

我怎样才能确保当我在框外点击警报时不会被解雇?

angular typescript ionic-framework ionic2 ionic3
3个回答
37
投票

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

是否应该通过点击背景来解除警报。默认为true

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

6
投票

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

backdropDismiss: false

1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.