【发布时间】:2017-05-11 18:10:39
【问题描述】:
我在我的应用程序和 ui-bootstrap 中使用 AngularJS (1.5.9)。 如果用户在已经打开的模式之外点击,我想显示一个确认弹出窗口。
我尝试使用$uibModalInstance.close() 的受控出口和$uibModalInstance.dismiss() 的非受控出口,但随后模式关闭,一旦我显示我的确认弹出窗口,就为时已晚。
尝试使用backdrop: 'static' 属性,但无法捕获模态窗口外的点击事件。
HTML:
<div ng-app="myApp">
<script type="text/ng-template" id="myModal.html">
<div class="modal-header">
<h3 class="modal-title">Modal title</h3>
</div>
<div class="modal-body">
Modal content
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">OK</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</script>
<div ng-controller="MyCtrl">
<input type="button" value="Show modal" ng-click="showModal()"/>
</div>
</div>
JS:
angular.module("myApp", ['ui.bootstrap'])
.controller("MyCtrl", function($scope, $modal) {
$scope.showModal = function(){
$modal.open({
templateUrl: 'myModal.html',
controller: 'ModalDialogController',
})
.result.then(
function () {
alert("OK");
},
function () {
alert("Cancel");
}
);
}
})
.controller("ModalDialogController", function ($scope, $modalInstance) {
$scope.ok = function () {
$modalInstance.close();
};
$scope.cancel = function () {
$modalInstance.dismiss('Cancel');
};
});
这是一个相关的小提琴 --> Fiddle
如您所见,一旦打开模态并单击外部,就会出现带有“取消”的警报,但我想弹出另一个模态以确认此操作以关闭模态,以防用户单击“取消”以前的模式保持打开状态。如果用户点击“确定”关闭两个模式。
有什么想法吗?
【问题讨论】:
标签: javascript angularjs angular-ui-bootstrap