【发布时间】:2020-08-01 02:13:29
【问题描述】:
我在 Angular 中使用 Bootstrap UI (https://angular-ui.github.io/bootstrap/) 中的模态组件来呈现模态,并且在关闭时我希望能够重定向到另一个状态,或者至少调用一个函数。
问题是我可以截获close 事件,但是每当我用户按下Esc 时,模式就会被解除,我找不到任何关于捕获dismiss 事件或为承诺分配函数的文档返回。
代码如下:
var modalInstance = $uibModal.open({
templateUrl: 'a-template.html',
controller: 'AnotherCtrl',
controllerAs: 'modal',
backdrop: false,
size: 'lg'
});
// I am able to catch this whenever the user exits the modal in an
// orthodox fashion. Doesn't happen when he presses Esc button.
modalInstance.closed = function () {
$state.go(homeState);
};
另外一种适合我的业务案例的解决方案是根本不允许用户关闭模式。并在模态控制器中发生事件时自行关闭它。到目前为止,我还没有找到这方面的功能。
【问题讨论】:
标签: angular-ui-bootstrap angular-ui-modal