AngularJS - 关闭模态窗口

标签 angularjs twitter-bootstrap angular-ui-bootstrap

我的包括:

bootstrap.css [ getbootstrap.com/2.3.2 ]
angular/ui-bootstrap-tpls-0.10.0.min.js from: [ angular-ui.github.io/bootstrap ]

我正在使用 AngularJS 和 Twitter Bootstrap。

从 AngularJS 我打开模态窗口如下:
var modalInstance = $modal.open({
              templateUrl: 'resources/html/mymodal.html',
              controller: 'mymodalController',
              scope: $scope
            });

我的模态模板是:
<div class="modal">
<
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
  </div>
.....
</div>

问题:
关闭 [x] 按钮不起作用
当我单击它时,模态不会消失。但是当我按下 Esc - 模式消失了。
所以看起来...... data-dismiss="modal"不起作用。有任何想法吗?

最佳答案

data-dismiss属性由 Bootstrap javascript 使用(我看到你从 http://getbootstrap.com/javascript/#modals 获得了 html 源代码)

UI Bootstrap 不会绑定(bind)到那个关闭按钮,因为它不是在寻找那个属性,你需要添加一个 ng-click 并像示例中那样关闭模式

http://angular-ui.github.io/bootstrap/#/modal

在 Controller 中:

$scope.cancel = function () {
    $modalInstance.dismiss('cancel');
};

模态模板...
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>

关于AngularJS - 关闭模态窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26154726/

相关文章:

html - Bootstrap 第二列与第一列重叠

css - 在 Docker 中使用自动构建无法使用 Bootstrap 进行样式化?

html - 在 HTML 中使用 Bootstrap

angularjs - 点击下载链接并关闭模式?

javascript - 将多个对象传递给 angularjs $resource.save()

php - Angularjs:显示对象数组

javascript - $broadcast 和 $on 不适用于基于 ng-if 的模板

angularjs - 当我离开时触发选项卡选择事件

javascript - 我如何使用带有 angularjs 1.6 组件的 bootstrap ui 分页

javascript - 使用 Ionic/UI-Router 难以达到子状态