Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close on modal Backdrop #1087

Closed
djds4rce opened this issue Apr 9, 2014 · 10 comments
Closed

Close on modal Backdrop #1087

djds4rce opened this issue Apr 9, 2014 · 10 comments

Comments

@djds4rce
Copy link

djds4rce commented Apr 9, 2014

How can we achieve closing the modal on modal backdrop click? I tried writing a directive to close the modal on backdrop click but the click event is never triggered. Any Suggestions?

@ajoslin
Copy link
Contributor

ajoslin commented Apr 9, 2014

Give this a try in a directive:

document.addEventListener('tap', function(event) {
  var target = angular.element(event.target);
  if (target.hasClass('modalbackdrop')) {
    $rootScope.$apply(function() {
      $rootScope.$broadcast('modal-backdrop-click');
    });
  }
});

Then catch that event in your controller.

@djds4rce
Copy link
Author

Hey Your code always has the target as HTML if we click on the backdrop. If we click on the modal it will give the proper modal element.

I modified the Example Code Pen to reporduce the same http://codepen.io/anon/pen/pqIba?editors=001

@ajoslin
Copy link
Contributor

ajoslin commented Apr 11, 2014

I'll wait until Adam commits the new tap refactor, then try this.

@ajoslin ajoslin self-assigned this Apr 11, 2014
@ajoslin
Copy link
Contributor

ajoslin commented Apr 30, 2014

Added!

@pjavvaji
Copy link

I don't want to hide the modal on backdrop click... Is there any attribute to set the flag, whether or not to hide the modal on backdrop click?

@pjavvaji
Copy link

I used popup to get the required behavior. Thanks.

@ajoslin
Copy link
Contributor

ajoslin commented May 12, 2014

My bad, I forgot to include the option.

Added.

@ghost
Copy link

ghost commented Jul 3, 2014

@ajoslin May I know the option to prevent the modal from hiding when I click the backdrop?

Thanks,
Praveen

@ghost
Copy link

ghost commented Jul 3, 2014

@ajoslin Gotacha!!! from your previous comment backdropClickToClose.

Thanks Again :)

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 6, 2018

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants