How do I prevent angular-ui modal from closing?

后端 未结 6 790
再見小時候
再見小時候 2021-01-30 05:15

I am using Angular UI $modal in my project http://angular-ui.github.io/bootstrap/#/modal

I don\'t want user to close the modal by pressing on backdrop. I want a modal

6条回答
  •  心在旅途
    2021-01-30 05:39

    Configure globally,

    decorator, one of the best features in angular. gives the ability to "patch" 3rd party modules.

    Let's say you want this behavior in all of your $modal references and you don't want to change your calls,

    You can write a decorator. that simply adds to options - {backdrop:'static', keyboard:false}

    angular.module('ui.bootstrap').config(function ($provide) {
        $provide.decorator('$modal', function ($delegate) {
            var open = $delegate.open;
    
            $delegate.open = function (options) {
                options = angular.extend(options || {}, {
                    backdrop: 'static',
                    keyboard: false
                });
    
                return open(options);
            };
            return $delegate;
        })
    });
    
    • Note: in the latest versions, the $modal renamed to $uibModal

    Online demo - http://plnkr.co/edit/2MWIpOs3uAG5EFQy6Ndn?p=preview

提交回复
热议问题