How not to close the notification window when clicking on it outside of Ionic

I am creating an ionic 2 application and using the following component

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 window, the warning is not rejected?

+18
source share
4 answers

Ionic 2/3:

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

enableBackdropDismiss : whether to disable the warning by touching the background. True by default

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:

Ionic 4 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();
  }
}
+40

ionic 4

backdropDismiss: false
+10

enableBackdropDismiss: false alertCtrl.create

+1

try like this, put this code for your handler handler: () => { console.log(this.viewCtrl.dismiss()); }

0
source

Source: https://habr.com/ru/post/1679920/


All Articles