【问题标题】:Angular-Strap Modal Does Not Load TemplateAngular-Strap 模态不加载模板
【发布时间】:2014-07-24 19:43:30
【问题描述】:

由于某种原因,模态框工作得很好,但它没有加载我指定的任何模板。

我的控制器有这个代码;

var brnSearchModal = $modal({ scope: $scope, template: "app/rrn/searchBrn.html", contentTemplate: false, html: true, show: false });

$scope.showModal = function () {
    brnSearchModal.$promise.then(brnSearchModal.show);
};

我的 HTML 看起来像这样;

<button data-ng-click="showModal()" type="button" class="btn btn-info" data-animation="am-fade-and-slide-top">
    BRN Lookup
</button>

我的模板在一个文件中,看起来像这样;

<div class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header" ng-show="title">
                <button type="button" class="close" ng-click="$hide()">&times;</button>
                <h4 class="modal-title" ng-bind="title">Hello, World!</h4>
            </div>
            <div class="modal-body" ng-bind="content">Lorem ipsum dolor.</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" ng-click="$hide()">Close</button>
            </div>
        </div>
    </div>
</div>

没有错误一切似乎工作正常,但模板没有加载。如果我在某一点调试 angular-strap,则模板已加载但随后消失并留下空白模式。

【问题讨论】:

    标签: javascript angularjs twitter-bootstrap angular-strap


    【解决方案1】:

    从模板中删除ng-show="title"ng-bind="title"

    【讨论】:

      【解决方案2】:

      尝试添加 bs-modal 属性:见examples

      <button data-ng-click="showModal()" type="button" class="btn btn-info" data-animation="am-fade-and-slide-top" bs-modal="brnSearchModal">
          BRN Lookup
      </button>
      

      否则直接使用data-template属性不使用JS显示模态:

      <button type="button" class="btn btn-info" data-animation="am-fade-and-slide-top" data-template="app/rrn/searchBrn.html" bs-modal="modal">
          BRN Lookup
      </button>
      

      我认为当你把 bs-modal="modal" modal 放在 angular-strap 库中时,它会以某种方式预先定义。

      【讨论】:

        【解决方案3】:

        您应该从模板中删除 ng-show="title" 、ng-show="content"ng-bind="title"。您应该确保模板中没有 ng-show

        【讨论】:

        • 如果要显示模态标题,请删除 ng-bind-html="title"
        【解决方案4】:

        我知道这是一个老问题,但万一其他人正在寻找解决同一问题的方法。我发现在将模板设置为 html 字符串时,我必须将 templateUrl 显式设置为 falsy

        【讨论】:

          猜你喜欢
          • 2015-10-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-09-24
          • 1970-01-01
          • 1970-01-01
          • 2016-02-23
          • 1970-01-01
          相关资源
          最近更新 更多