使用引导程序关闭angular.js中的所有对话框 [英] Close all dialog boxes in angular.js with bootstrap

查看:118
本文介绍了使用引导程序关闭angular.js中的所有对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个示例,其中通过单击显示模态"按钮来生成对话框,此处已加载对话框,然后,如果单击此模态的按钮打开其他模态",则第二个对话框打开.单击任何模式的取消"按钮时,需要它,然后关闭对话框.当前正在打开第二个对话框,如果我单击取消",则仅关闭第二个对话框,当我尝试在第一个对话框中单击取消"时,它不会关闭.我能做什么?

I have an example in which a dialog box is generated, by clicking on the "show modal" button, here the dialog box is loaded, then if I click on the button of this modal called "open other modal", the second dialog Box is open. I need it when I click the cancel button of any modal, close the dialog box. Currently having the second dialog box open, if I click cancel, only the second is closed, when I try to click cancel in the first dialog box, it will not close. What I can do?

var modalInstance = null;
var modalScope = $scope.$new();

$scope.close = function (ok, hide) {
    if(ok) {
        //alert('ok');
    } else {
        //alert('cancel');
    }
    modalInstance.dismiss();
};

$scope.showModal = function() {    
     modalInstance = $modal.open({
         templateUrl: 'myModal.html',
         scope: modalScope
     });
}

$scope.otherModal = function() {    
     modalInstance = $modal.open({
         templateUrl: 'myModal2.html',
         scope: modalScope
     });
}

http://fiddle.jshell.net/9bum7snh/

推荐答案

您需要跟踪正在创建的模态.这是一个将模态保存在数组中的简单示例.可能有更好的解决方案,但这为您提供了有关如何解决问题的提示.

You need to keep track of the modals you are creating. Here is a quick example were the modals are kept in an array. There are probably much better solutions, but this gives you a hint on how to solve your problem.

    var modalInstances = [];
    var modalScope = $scope.$new();

    $scope.close = function (ok, hide) {
        if(ok) {
            //alert('ok');
        } else {
            //alert('cancel');
        }
        if(modalInstances.length > 0){
          modalInstances[modalInstances.length-1].dismiss();
          modalInstances.pop();
        }

    };


    $scope.showModal = function() {    
         modalInstances.push($modal.open({
             templateUrl: 'myModal.html',
             scope: modalScope
         }));
    }

    $scope.otherModal = function() {    
         modalInstances.push($modal.open({
             templateUrl: 'myModal2.html',
             scope: modalScope
         }));
    }

这篇关于使用引导程序关闭angular.js中的所有对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆