我在我的项目中使用角用户界面/引导模式。
这是我的模式:
$scope.toggleModal = function () {
$scope.theModal = $modal.open({
animation: true,
templateUrl: 'pages/templates/modal.html',
size: "sm",
scope: $scope
});
}可以通过单击ESC按钮或单击模态区域外部来关闭模态。在发生这种情况时,是否有一种运行函数的方法?我不太清楚怎样才能赶上这样的结束。
我知道,通过拥有这样的ng-click="closeModal()",我可以手动取消一个模式:
$scope.closeModal = function () {
$scope.theModal.dismiss('cancel');
};发布于 2015-05-20 17:53:46
是的你可以。这会导致解雇事件,在这种情况下,承诺被拒绝。另外,请注意,$modal.open()方法返回一个具有result属性的对象。
有了承诺你可以..。
//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
});作为一种快捷方式,您可以编写:
$scope.theModal.result.then(doClosureFn, doDismissFn);open方法返回一个模态实例,该对象具有以下属性:
发布于 2016-03-16 11:55:37
老问题,但是如果要在各种关闭操作上添加确认对话框,请将其添加到模态实例控制器中:
$scope.$on('modal.closing', function(event, reason, closed) {
console.log('modal.closing: ' + (closed ? 'close' : 'dismiss') + '(' + reason + ')');
var message = "You are about to leave the edit view. Uncaught reason. Are you sure?";
switch (reason){
// clicked outside
case "backdrop click":
message = "Any changes will be lost, are you sure?";
break;
// cancel button
case "cancel":
message = "Any changes will be lost, are you sure?";
break;
// escape key
case "escape key press":
message = "Any changes will be lost, are you sure?";
break;
}
if (!confirm(message)) {
event.preventDefault();
}
});我的右上角有一个关闭按钮,它触发了“取消”操作。单击背景(如果启用),将触发取消操作。您可以使用它对各种关闭事件使用不同的消息。我想我应该和大家分享一下,以防对别人有帮助。
发布于 2015-05-20 17:57:05
您可以使用$modal.open()方法返回的“结果”承诺。如下所示:
$scope.toggleModal = function () {
$scope.theModal = $modal.open({
animation: true,
templateUrl: 'pages/templates/modal.html',
size: "sm",
scope: $scope
});
$scope.theModal.result.then(function(){
console.log("Modal Closed!!!");
}, function(){
console.log("Modal Dismissed!!!");
});
}您还可以使用“结果”的“最终”回调,如下所示:
$scope.theModal.result.finally(function(){
console.log("Modal Closed!!!");
});https://stackoverflow.com/questions/30356844
复制相似问题