15

I'm building a simple mobile app that passes data between a homepage and a modal page. While it works great on mobile, on a large screen, the modal doesn't fill the whole screen. So the user is able to click outside the screen to dismiss the modal which doesn't trigger any of my functions that that are supposed to trigger on modal dismiss. My question is, how do a disable clicking outside the modal. I don't want the modal to dismiss on click outside, but only when my "close" button is clicked. My modal is set up as:

On HomePage:

open(){
    let modal = this.modalCtrl.create(ModalPage,
        {
            firstName: this.user.firstName,
            lastName: this.user.lastName,
            location: this.user.location
        });
    modal.onDidDismiss(data => {
            this.user.firstName = data.firstName;
            this.user.lastName = data.lastName;
            this.user.location = data.location;
    });
    modal.present();
}

On ModalPage:

closeModal() {
    let data = {
        firstName: this.user.firstName,
        lastName: this.user.lastName,
        location: this.user.location
    }
    this.viewCtrl.dismiss(data);
}

I feel like this should be something very simple, but I can't find any resources online, and the Ionic 2 Doc isn't very clear. Please help.

3 Answers 3

36

Make use of the enableBackdropDismiss-option when creating the modal (link to docs).

let modal = this.modalCtrl.create(ModalPage, { data: data }, { enableBackdropDismiss: false });

ionic 4

const modal = await this.modalCtrl.create({
  component: ModalPage,
  componentProps: {
    'data': this.data 
  },
  backdropDismiss:false
});
2
  • Ah hah, the enableBackdropDismiss has to go in as an object. Of course! Thank you! Commented Jul 21, 2017 at 22:23
  • 3
    In latest angular version it is backdropDismiss Commented May 9, 2019 at 10:12
12

For ionic 4

backdropDismiss:false,

the model should be created like this

 const modal = await this.modalCtrl.create({
      component: SetaddresComponent,
      cssClass: 'my-custom-modal-css',
      componentProps: { },
      showBackdrop:true,
      backdropDismiss:false,
    },
0

My problem is solved using below code in the Ionic 6

<ion-modal [isOpen]="true" [swipeToClose]="true" [backdropDismiss]="false" [breakpoints]="[0.1, 0.3, 1]"  [initialBreakpoint]="0.3">

This is main keyword for that

[backdropDismiss]="false"

Not the answer you're looking for? Browse other questions tagged or ask your own question.