Pet*_*ron 13 modal-dialog angularjs angular-ui-bootstrap
如何检测何时关闭Angular UI Bootstrap模式对话框?
我需要知道对话框什么时候关闭所以我可以loginCancelled使用angular-http-auth库来广播一个事件,以防止我的Angular UI挂起,特别是在通过点击背景关闭模态之后.
wak*_*rth 16
这适用于单击背景并按esc键,如果您正在选择.
var modalInstance = $modal.open({
templateUrl: '/app/yourtemplate.html',
controller: ModalInstanceCtrl,
windowClass: 'modal',
keyboard: true,
resolve: {
yourResulst: function () {
return 'foo';
}
}
});
var ModalInstanceCtrl = function ($scope, $modalInstance, yourResulst) {
var constructor = function () {
// init stuff
}
constructor();
$modalInstance.result.then(function () {
// not called... at least for me
}, function () {
// hit's here... clean up or do whatever
});
// VVVV other $scope functions and so on...
};
Run Code Online (Sandbox Code Playgroud)
更新:替代方法
我不知道为什么这种方式没有记录在http://angular-ui.github.io/bootstrap/ ...但我发现它好多了.您现在可以使用该页面的控制器或使用控制器的特定控制器作为语法.如果你想在html上分离,你甚至可以使用ng-include作为模态的内容.只要您的项目/站点中包含bootstrap/bootstrapUI,以下工作在控制器中不需要JS来设置/配置模态
<div class="row">
<button class="btn btn-default" data-toggle="modal" data-target="#exampleModal">Open Example Modal</button>
</div>
<div class="modal fade" id="exampleModal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">Close</button>
<h2 class="modal-title" id="exampleModalLabel">Modal Example</h2>
</div>
<div class="modal-body" style="padding-bottom:0px;">
<h3>model markup goes here</h3>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
Raf*_*tta 10
我完成了以下代码:
$modal.open(modalOptions).result.finally(function(){
console.log('modal has closed');
});
Run Code Online (Sandbox Code Playgroud)
这样你可以避免使用方法()
| 归档时间: |
|
| 查看次数: |
29103 次 |
| 最近记录: |