我使用的是角UI /自举模式在我的项目。
I am using the Angular-ui/bootstrap modal in my project.
下面是我的模式:
$scope.toggleModal = function () {
$scope.theModal = $modal.open({
animation: true,
templateUrl: 'pages/templates/modal.html',
size: "sm",
scope: $scope
});
}
一个人可以通过单击的 ESC 的按钮或点击模式禁区外关闭模式。有没有办法运行功能时出现这种情况?我不太清楚如何捕捉到那种闭幕。
One is able to close the modal by clicking the ESC button or clicking outside the modal area. Is there a way to run a function when this happens? I am not quite sure how to catch the sort of closing.
我知道我可以手动有一个驳回模式NG点击=closeModal()
是这样的:
I know that I can manually dismiss a modal by having a ng-click="closeModal()"
like this:
$scope.closeModal = function () {
$scope.theModal.dismiss('cancel');
};
如果有人可以帮助,这将是极大的AP preciated。
If anyone could help, it would be greatly appreciated.
当然可以。这导致解雇事件,并承诺在这种情况下拒绝。也并不是说 $ modal.open
返回与它的属性之一的对象,结果
,是一种承诺。比如你可以这样做:
Yes you can. It causes a dismiss event and the promise is rejected in that case. Also not that $modal.open
returns an object with one of the properties in it ,result
, is a promise .I.e you could do:
//This will run when modal dismisses itself when clicked outside or
//when you explicitly dismiss the modal using .dismiss function.
$scope.theModal.result.catch(function(){
//Do stuff with respect to dismissal
});
//Runs when modal is closed without being dismissed, i.e when you close it
//via $scope.theModal.close(...);
$scope.theModal.result.then(function(datapassedinwhileclosing){
//Do stuff with respect to closure
});
作为快捷方式,你可以写:
as a shortcut you could write:
$scope.theModal.result.then(doClosureFn, doDismissFn);
见参考文献
open方法返回一个模式的实例,具有以下属性的对象:
The open method returns a modal instance, an object with the following properties: 关闭(结果) - 可以用来关闭模式的方法,通过结果 关闭(原因) - 可用于关闭模态的方法,传递一个原因 的结果 - 当一个模式被驳回时,一个模式是封闭的得到解决,拒绝承诺 打开 - 一个承诺,当一个模式被下载内容的模板,并解决所有变量后,打开的解决 渲染 - 当一个模式被渲染被解决的承诺