[英]How to detect closing a modal window in $modal? angular-ui
I am using the $modal
in angular-ui to create a modal window her is the code for creating the model. 我在angular-ui中使用$modal
创建一个模态窗口,她是创建模型的代码。
this.show = function (customModalDefaults, customModalOptions, extraScopeVar) {
//Create temp objects to work with since we're in a singleton service
var tempModalDefaults = {};
var tempModalOptions = {};
//Map angular-ui modal custom defaults to modal defaults defined in service
angular.extend(tempModalDefaults, modalDefaults, customModalDefaults);
//Map modal.html $scope custom properties to defaults defined in service
angular.extend(tempModalOptions, modalOptions, customModalOptions);
if (!tempModalDefaults.controller) {
tempModalDefaults.controller = function ($scope, $modalInstance) {
$scope.modalOptions = tempModalOptions;
$scope.extraScopeVar = extraScopeVar;
$scope.modalOptions.ok = function (result) {
$modalInstance.close(result);
};
$scope.modalOptions.close = function (result) {
$modalInstance.dismiss('cancel');
};
}
}
return $modal.open(tempModalDefaults).result;
};
till now every thing is working fine. 到现在为止,一切正常。 the model have close and dismiss which run when i hit cancel or OK on the modal window. 当我在模态窗口中单击“取消”或“确定”时,模型已关闭并关闭。 the problem is when i press a click outside modal window it gets disappear that what i want but i also what to know which method runs on that case to override it for custom behavior like which i am doing with OK and Close 问题是,当我在模态窗口外单击时,它消失了,我想要的东西消失了,但是我也知道在那种情况下运行哪种方法以针对自定义行为覆盖它,例如我使用OK和Close
$modal.open(tempModalDefaults).result
is a promise. 是一个承诺。 When the backdrop option is set to 'true', the promise will be rejected. 当背景选项设置为“ true”时,承诺将被拒绝。 You can can attach a rejection handler to that promise by using either the then method or the catch method which is shortcut: 您可以使用then方法或catch方法(快捷方式)将拒绝处理程序附加到该诺言:
catch(errorCallback) – shorthand for promise.then(null, errorCallback) catch(errorCallback)– Promise.then的简写(null,errorCallback)
return $modal.open(tempModalDefaults).result.catch(function (reason) {
// your code to handle rejection of the promise.
if (reason === 'backdrop') {
// do something
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.