Ionic 2 click on modal background dismiss function not working


#1

i try to pass the data when modal close. when i click the button close modal it working, but if i click on background, modal is close, but the data is not pass back to the view. because i build the ios for ipad, so i need to take care if user click on background to close modal, they also can get the data.

here is my code

dismiss() {
let data = {title: “hello”};
console.log(‘213131’);
this.viewCtrl.dismiss(data);
}

is there a way to detect the modal background click?


#2

Did you find any solution?


#3

digging around, and i found some result.
modal have two advanced option showBackdrop and endableBackdropDismiss.

for some reason we don’t need click background to get the data, click background mean, user give up data. so we decided to add a button on modal, if user want to pass data, then click the button.

if you still want to do so, here is result

let modal = this.modalCtrl.create(ModalContentPage, { charNum: 0, hello: catInfo }, {showBackdrop: true, enableBackdropDismiss: true});

enableBackdropDismiss will do the job for you. :slight_smile: