angularjs – Angular UI Bootstrap Modal – 如何防止多个模态打开

前端之家收集整理的这篇文章主要介绍了angularjs – Angular UI Bootstrap Modal – 如何防止多个模态打开前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经实现了模态指令,并将$modal.open选项背景设置为false.但是,现在我可以触发多个模态打开.有一种方法可以防止触发按钮在一个模态打开后触发吗?
var accountSummaryCtrl = function ($scope,$modal,$log) {

    $scope.open = function () {

        var modalInstance = $modal.open({
            templateUrl: '/Apps/generic/modal/Templates/AccountSummary.html',controller: ModalInstanceCtrl,backdrop: false
        });

        modalInstance.result.then(function (selectedItem) {
            $scope.selected = selectedItem;
        },function () {
            $log.info('Modal dismissed at: ' + new Date());
        });
    };
};

谢谢

使用布尔标志来避免它:
var accountSummaryCtrl = function ($scope,$log) {

    var opened = false;

    $scope.open = function () {

        if (opened) return;

        var modalInstance = $modal.open({
            templateUrl: '/Apps/generic/modal/Templates/AccountSummary.html',backdrop: false
        });

        opened = true;

        modalInstance.result.then(function (selectedItem) {
            $scope.selected = selectedItem;
            opened = false;
        },function () {
            $log.info('Modal dismissed at: ' + new Date());
            opened = false;
        });
    };
};
原文链接:https://www.f2er.com/angularjs/140876.html

猜你在找的Angularjs相关文章