68

Am using the angular bootstrap to present a modal. But my requirement is to prevent pop-up dismissal when clicking outside the modal, or when the escape key is pressed.

I followed the tutorial on the angular bootstrap site :http://angular-ui.github.io/bootstrap/

enter image description here

3 Answers 3

132

Use:

backdrop: 'static'

backdrop - controls presence of a backdrop. Allowed values: true (default), false (no backdrop), 'static' - backdrop is present but modal window is not closed when clicking outside of the modal window.

For example:

$modal.open({
      templateUrl: 'myModalContent.html',
      controller: ModalInstanceCtrl,
      backdrop: 'static'
    })
1
  • 1
    Works without a doubt as the answer below confirms Commented May 21, 2015 at 22:43
46

Add both backdrop: static and keyboard: false to your modal options. The first one disables the background click, the second one the escape key.

backdrop: 'static' - backdrop is present but modal window is not closed when clicking outside of the modal window.

keyboard - indicates whether the dialog should be closable by hitting the ESC key, defaults to true.

Example:

$modal.open({
  templateUrl: 'template.html',
  controller: TheController,
  backdrop: 'static',
  keyboard: false
})

See the docs for more information.

2
  • 6
    This should be the accepted answer as it resolves both of the requirements as outlined by the OP.
    – boardlemur
    Commented Mar 21, 2016 at 15:10
  • As said, the best and more broad answer Commented Apr 25, 2019 at 18:01
10

"backdrop - controls presence of a backdrop. Allowed values: true (default), false (no backdrop), 'static' - backdrop is present but modal window is not closed when clicking outside of the modal window." - in http://angular-ui.github.io/bootstrap/#/modal

Try:

<div ng-controller="ModalDemoCtrl" data-backdrop="static">
...
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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