有没有办法拦截BootstapUI的$ uibModal关闭事件? [英] Is there a way to intercept BootstapUI's $uibModal dismissed event?
问题描述
我正在使用Bootstrap UI中的模式组件( https://angular-ui.github. io/bootstrap/)在Angular中渲染模式,并且在关闭时我希望能够重定向到另一个状态,或者至少要调用一个函数.
问题是我可以拦截close
事件,但是每当我按下Esc
时,模态都会被关闭,并且找不到任何捕获dismiss
事件或将函数分配给promise的文档.返回.
代码如下:
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);
};
或者,适合我的业务情况的另一种解决方案是完全不允许用户忽略该模式.并在模态控制器中发生事件时自行关闭它.到目前为止,我都没有找到功能.
在与模式相关联的控制器中(对于您来说是"AnotherCtrl"或"modal"),可以将$scope.$on()
与'modal.closing'
事件一起使用./p>
示例:
var modalInstance = $uibModal.open({
templateUrl: 'a-template.html',
controller: ['$scope', function($scope){
$scope.$on('modal.closing', function(event, reason, closed){
if('condition for not closing')
event.preventDefault(); //You can use this to prevent the modal from closing
else
window.location = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
});
}],
controllerAs: 'modal',
backdrop: false,
size: 'lg'
});
I'm using the modal compoenent from Bootstrap UI (https://angular-ui.github.io/bootstrap/) in Angular to render a modal, and on closing I want to be able to redirect to another state, or at least have a function be called.
The problem is I can intercept the close
event but whenever I user presses Esc
the modal is dismissed and I couldn't find any documentation of catching the dismiss
event or assigning a function to the promise that is returned.
The code is as follows:
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);
};
Alternatively another solution that would suit my business case would be to simply not allow the user to dismiss the modal. And close it myself whenever an event happens in the modal controller. I neither found functionality for this so far.
In the controller associated with the modal ("AnotherCtrl" or "modal" for you), you can use $scope.$on()
with the 'modal.closing'
event.
Example:
var modalInstance = $uibModal.open({
templateUrl: 'a-template.html',
controller: ['$scope', function($scope){
$scope.$on('modal.closing', function(event, reason, closed){
if('condition for not closing')
event.preventDefault(); //You can use this to prevent the modal from closing
else
window.location = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
});
}],
controllerAs: 'modal',
backdrop: false,
size: 'lg'
});
这篇关于有没有办法拦截BootstapUI的$ uibModal关闭事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!