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
});
}
You can give them a different variable name and then pass them into your close function in the template. Then conditionally dismiss them, please see below.
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.