我正在使用Angular UI引导模式对话框,并在服务中创建它:
myApp.factory('ModalService', ['$modal', function($modal) { return { trigger: function(template) { $modal.open({ templateUrl: template, size: 'lg', controller: function($scope, $modalInstance) { $scope.ok = function() { $modalInstance.close($scope.selected.item); }; $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; } }); }, close: function() { // this should close all modal instances } }; }]);
ModalService.close()从控制器或任何其他方式调用时,如何关闭所有模式实例?
ModalService.close()
注入$modalStack服务并调用函数$modalStack.dismissAll(),有关详细信息,请参见GitHub上的代码:
$modalStack
$modalStack.dismissAll()
myApp.factory('ModalService', ['$modal', '$modalStack' function($modal, $modalStack) { return { trigger: function(template) { $modal.open({ templateUrl: template, size: 'lg', controller: function($scope, $modalInstance) { $scope.ok = function() { $modalInstance.close($scope.selected.item); }; $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; } }); }, close: function(reason) { $modalStack.dismissAll(reason); } }; }]);