gpt4 book ai didi

angularjs - 根据模态 Controller 内部的逻辑防止 AngularJS 模态关闭

转载 作者:行者123 更新时间:2023-12-03 18:24:35 28 4
gpt4 key购买 nike

有没有办法防止 AngularJS 模态在模态的 Controller 逻辑中关闭/关闭?

我想要的是当用户关闭模态并且模态内的表单包含未保存的数据时显示警告。

我已经尝试搜索关闭前事件或我可以在 official documentation 中使用的其他内容,但到目前为止还没有运气。

最佳答案

您可以观看广播到模态范围的“modal.closing”事件,如下所示:

.controller('modalCtrl', function($scope, $modalInstance) {

$scope.$on('modal.closing', function(event, reason, closed) {
var r = prompt("Are you sure you wanna close the modal? (Enter 'YES' to close)");

if (r !== 'YES') {
event.preventDefault();
}
});
})

第一个参数是事件,您可以preventDefault() 来防止它关闭。

第二个参数是原因(传递给$close()方法的任何东西)

第三个参数是一个 bool 值,表示模式是关闭还是关闭。

这里是工作 plunker

这个不知道是什么时候添加的,目前官方文档中有提到。

关于angularjs - 根据模态 Controller 内部的逻辑防止 AngularJS 模态关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28429499/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com