我正在使用 Angular 带创建一个模态,例如:
$modal({
template : "/templ/alert-with-title.html",
content : content,
title : title,
show : true,
backdrop : true,
placement : 'center'
});
我写了以下内容:
$scope.$on("modal.hide.before",function() {
console.log("Closing1");
});
$scope.$on("modal.hide",function() {
console.log("Closin2");
});
我的/templ/alert-with-title.html
是这样的:
<div aria-hidden="true" aria-labelledby="windowTitleLabel" role="dialog"
tabindex="-1" class="modal hide fade in modal" id="">
<div class="modal-header">
<a class="fui-cross pull-right" ng-click="$hide()"></a>
<h3 ng-bind="title"></h3>
</div>
<div class="modal-body">
<div class="divDialogElements" >
<span ng-bind="content"></span>
</div>
</div>
<div class="modal-footer">
<div>
<button type="button" ng-click="$hide()"
class="btn btn-default btn-gray-l gray pull-left mar_t-4">OK</button>
</div>
</div>
</div>
但是,即使在这一切之后,当我单击“确定”时,我也没有收到任何控制台日志。这是为什么?
最佳答案
所以解决方案非常简单,我必须向 $modal 提供范围。
$modal({
template : "/templ/alert-with-title.html",
content : content,
title : title,
show : true,
backdrop : true,
placement : 'center',
scope : $scope
});
但我不明白为什么对于“$emit”事件,外部范围的 $on 不起作用
关于angularjs - 在 Angular 带的$modal中捕获隐藏事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32228725/