angularjs - 在 Angular 带的$modal中捕获隐藏事件

标签 angularjs modal-dialog angular-strap

我正在使用 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/

相关文章:

javascript - 使用自定义指令在 Angular 引导日期选择器上禁用周末日期

css - Angular UI Bootstrap 时间和日期选择器 popus 显示在输入下方

javascript - AngularJS 观察指令属性表达式,动态继承作用域

javascript - AngularJS 自定义指令 - Controller 变量 'crosstalk'

php - 停止页内操作的 Jquery 模式对话框

javascript - 在 Enter 键上确认 Jquery UI 对话框提示

angularjs - Angular UI Bootstrap 与 AngularStrap 与 Bootstrap

angularjs - key 工具 : command not found

javascript - 将 $http 响应分配给 $scope 时,AngularJS View 不会更新

javascript - 如何从 javascript 函数中显示 Bootstrap 模式?