我在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);
};
或者,适合我的业务案例的另一种解决方案是根本不允许用户关闭模式。并在模态控制器中发生事件时自行关闭它。到目前为止,我还没有找到这方面的功能。