Angularjs 如何防止角度UI引导模式关闭?
我有一个Angularjs 如何防止角度UI引导模式关闭?,angularjs,modal-dialog,angular-ui,Angularjs,Modal Dialog,Angular Ui,我有一个$modalInstance。在承诺的帮助下,我可以收到关闭事件通知: $modalInstance.result.finally(function() { // code here }); 但我不知道如果用户错误地关闭模型,如何防止关闭。我想问用户是否真的想关闭模型,如果他真的想关闭它。我仍然不想启用background:“static”: $modal.open({ ... // other options backdrop : 'static' }); 谢谢。我做了
$modalInstance
。在承诺的帮助下,我可以收到关闭事件通知:
$modalInstance.result.finally(function() {
// code here
});
但我不知道如果用户错误地关闭模型,如何防止关闭。我想问用户是否真的想关闭模型,如果他真的想关闭它。我仍然不想启用background:“static”
:
$modal.open({
... // other options
backdrop : 'static'
});
谢谢。我做了更多的研究,发现与此类似,这是关于这个问题的答案(请随意+1他,而不是我) 将其放入模态控制器中 这并不完全是您搜索的内容,如果您试图关闭模式,则会提示您关闭(单击“模式外”)、取消或确定按钮。您可以尝试修改它以满足您的需要 更新:添加了简单的
if-else
检查单击了什么,如果单击了background,则提示用户:
$scope.$on('modal.closing', function(event, reason, closed) {
if (reason == 'ok' || reason == 'cancel'){
console.log('closed');
} else {
// this is if 'reason' == 'backdrop click'
var r = prompt("Are you sure you wanna close the modal? (Enter 'YES' to close)");
if (r !== 'YES') {
event.preventDefault();
}
}
});
你认为这个解决方案足够吗 当你关闭一个事件触发的模式时,在我看来,你可以以某种方式处理它,我认为这个问题可以帮助你:我认为没有必要使用boostrap的模式。您只需创建z索引大于零的div/form。并根据需要使用ng hide/ng show使隐藏/可见。@SaiGiridhar嗯,我必须在项目中使用它,这是一项要求。上一次我做模态分析时,只有VanillaJS:)@user3266024我看了之后没有看到答案,稍后会仔细阅读答案,谢谢。
$scope.$on('modal.closing', function(event, reason, closed) {
if (reason == 'ok' || reason == 'cancel'){
console.log('closed');
} else {
// this is if 'reason' == 'backdrop click'
var r = prompt("Are you sure you wanna close the modal? (Enter 'YES' to close)");
if (r !== 'YES') {
event.preventDefault();
}
}
});