How do I prevent angular-ui modal from closing? How do I prevent angular-ui modal from closing? angularjs angularjs

How do I prevent angular-ui modal from closing?


While you creating your modal you can specify its behavior:

$modal.open({   // ... other options   backdrop  : 'static',   keyboard  : false});


backdrop : 'static'

Will work for 'click' events but still you can use "Esc" key to close the popup.

keyboard :false

to prevent popup close by "Esc" key.

Thanks to pkozlowski.opensource for answer.

I think question is duplicate of Angular UI Bootstrap Modal - how to prevent user interaction


Old question, but if you want to add confirmation dialogs on various close actions, add this to your modal instance controller:

$scope.$on('modal.closing', function(event, reason, closed) {    console.log('modal.closing: ' + (closed ? 'close' : 'dismiss') + '(' + reason + ')');    var message = "You are about to leave the edit view. Uncaught reason. Are you sure?";    switch (reason){        // clicked outside        case "backdrop click":            message = "Any changes will be lost, are you sure?";            break;        // cancel button        case "cancel":            message = "Any changes will be lost, are you sure?";            break;        // escape key        case "escape key press":            message = "Any changes will be lost, are you sure?";            break;    }    if (!confirm(message)) {        event.preventDefault();    }});

I have a close button on the top right of mine, which triggers the "cancel" action. Clicking on the backdrop (if enabled), triggers the cancel action. You can use that to use different messages for various close events.