angularjs - Angular 模态 : add template from another html

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

我在另一个 html 文件中有一个模态模板,但是在第一次加载页面后,模态窗口打开时没有内容,第二次一切正常。如何解决这个问题?

这是 plunker http://plnkr.co/edit/lw056nAaU7BfqIVZSddb?p=preview

//Open modal on main page with:
<div ng-controller="ModalDemoCtrl">
<button type="button" class="btn btn-default" ng-click="open()">Open me!</button>
<button type="button" class="btn btn-default" ng-click="open('lg')">Large modal</button>
<button type="button" class="btn btn-default" ng-click="open('sm')">Small modal</button>
<button type="button" class="btn btn-default" ng-click="toggleAnimation()">Toggle Animation ({{ animationsEnabled }})</button>
<div ng-show="selected">Selection from a modal: {{ selected }}</div>

最佳答案

你不应该用 <script type="text/ng-template" id="myModalContent.html"></script> 包裹你的模板.

Ui-modal 在这里需要直接的 HTML。

如果你需要使用 ng-template,你应该在你的 index.html(或其他任何地方,但它应该被加载到你的页面)中插入 ng-template 脚本标签,然后用 template 打开你的模态。而不是 templateUrl这边走 :

var modalInstance = $uibModal.open({
      animation: $scope.animationsEnabled,
      template: "<div ng-include src=\"'myModalContent.html'\"></div>",
      controller: 'ModalInstanceCtrl',
      size: size,
      resolve: {
        items: function () {
          return $scope.items;
        }
      }
});

关于angularjs - Angular 模态 : add template from another html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36641986/

相关文章:

arrays - Angular 1.3 过滤具有数组属性的对象列表

javascript - 模式打开时复制到剪贴板操作不起作用

jquery - 具有不同按钮的多个 Bootstrap 模式链接到各自的内容不起作用

javascript - 将标题添加到 Bootstrap 响应式模态图像库

angularjs - 如果空白,带有 md-chips 的 Angular Material md-autocomplete 不会清除搜索

angularjs - 将 ng-grid 数据导出为 CSV 和 PDF 格式

javascript - 当输入字段位于 ng-repeat 中时,ng-disabled 不起作用

javascript - 组织 AngularJS Controller

javascript - 带有 AJAX 多重选择的 Angular ui-select2 - 将最终选择值检索为 ids 而不是 json

angularjs - 如何在 ngtable( Angular 插件)中设置动态数据标题