【问题标题】:How do I integrate the bootstrap-modal plugin with AngularUI Bootstrap如何将 bootstrap-modal 插件与 AngularUI Bootstrap 集成
【发布时间】:2013-08-29 18:44:07
【问题描述】:

我正在将基于 jQuery 的 Web 应用程序迁移到 AngularJS。我无法将 bootstrap-modal plugin 与 AngularUI Bootstrap 集成。 bootstrap-modal 插件提供了一些我需要的功能:全宽模式、响应式设计和可堆叠模式。

我已经在plunker 上进行了将两者集成的基本尝试。请注意,当窗口宽度较小时,模态显示为全角。但是,如果您弹出 plunker 预览窗口并将窗口宽度增加到 ~979px 以上,则模态框会下降一半页面。我可以在 bootstrap-modal 源代码中看到 CSS 将模态设置为“top:50%”,但是 JS 应该根据模态高度设置负边距顶部,因此模态在中心垂直对齐的页面。 JS 没有被正确调用,因此模式向页面底部倾斜。

下面 plunker 的代码 sn-ps。

HTML:

<div ng-controller="ModalDemoCtrl">
    <button class="btn" ng-click="open()">Open me!</button>
    <div modal="shouldBeOpen" close="close()" options="opts">
        <div class="modal-header">
            <button type="button" ng-click="close('edit')" class="close" data-dismiss="modal">x</button>
            <h3>I'm a modal!</h3>
        </div>
        <div class="modal-body">
            <ul>
                <li ng-repeat="item in items">{{item}}</li>
            </ul>
        </div>
        <div class="modal-footer">
            <button class="btn btn-warning cancel" ng-click="close()">Cancel</button>
        </div>
    </div>
</div>

JavaScript 控制器:

angular.module('plunker', ['ui.bootstrap']);
var ModalDemoCtrl = function ($scope) {

  $scope.open = function () {
    $scope.shouldBeOpen = true;
  };

  $scope.close = function () {
    $scope.closeMsg = 'I was closed at: ' + new Date();
    $scope.shouldBeOpen = false;
  };

  $scope.items = ['item1', 'item2'];

  $scope.opts = {
    backdropFade: true,
    dialogFade:true
  };

};

替代方法看起来不使用 AngularUI Bootstrap,而只是使用引导程序的常规方法在模态 HTML 中编码。我发现这个jsFiddle 在仍然使用AngularJS 的同时确实做到了这一点。如果可能的话,我更喜欢使用 AngularUI 方法。

【问题讨论】:

  • 对于那些今天阅读本文的人,请注意,自angular-ui 0.6 以来,modal 指令已变成服务。这段代码现已弃用

标签: twitter-bootstrap angularjs angular-ui angular-ui-bootstrap bootstrap-modal


【解决方案1】:

【讨论】:

  • +1。您的模式服务看起来很有希望。不幸的是,我还没有准备好切换到 bootstrap 3.0。您的模态服务是否向后兼容 bootstrap 2.x(即 2.3.2)?
  • 我最终使用了这个。我将它分叉并添加代码以使模态全高类似于 bootstrap-modal 提供的。 github.com/ravishivt/ngEkathuwa。谢谢@sarath2!
【解决方案2】:

问题在于您的 bootstrap-modal.css 响应部分:@media (max-width: 979px){...},如果您不想要它,则通过将 (max-width 更改为min-width) 或者只是复制该部分代码并稍后在您的 html 中覆盖它。

【讨论】:

  • 感谢 Noogen,但修改 CSS 并不能真正解决我的问题。问题是 AngularUI Bootstrap 框架不能很好地与 bootstrap-modal javascript 代码配合使用。它似乎根本没有调用它。 CSS 修改可能会修复模态显示的某些极端情况,但不会修复 bootstrap-modal 必须提供的缺失功能。
  • 是的,AngularUI 示例非常通用且特定于引导程序,因此可能很难以您想要的方式使用。由于您使用几乎不同或增强的模态插件,您可以编写自己的指令或找到增强 AngularUI $dialog 服务的方法。
  • +1,感谢 Noogen。我希望有人已经这样做了,因为它是一个流行的插件,但看起来我得动手了。
猜你喜欢
  • 1970-01-01
  • 2014-03-05
  • 1970-01-01
  • 2013-01-24
  • 2019-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-14
相关资源
最近更新 更多