javascript - 拉入本地 html 内容的 AngularJS bootstrap-ui 选项卡

标签 javascript html angularjs angular-ui-bootstrap

我已经设置了一个简单的应用程序,现在我想引入一个本地 html 文件作为每个选项卡的内容。我也只希望“苹果”内容显示在“苹果”选项卡下,梨也一样,让我的 html 尽可能简单,因为将来可以添加更多水果。

请查看我当前配置的 plunker: http://plnkr.co/edit/Y6Ey8vbvrq3xzvBhJS7o?p=preview

  <tab ng-repeat="tab in tabs" heading="{{tab.title}}" select="getContent($index)" active="tab.active" disabled="tab.disabled">
  <div ng-hide="!tabs.isLoaded">
  <h1>{{tab.title}}</h1>
    <div ng-repeat="item in tabs.content">
      <p>{{item[tab.title]}}</p>
    </div>
  </div>
  <div ng-hide="tabs.isLoaded"><h3>Loading...</h3></div>
  </tab>

我的问题是,你能帮我确定如何只提取属于一个 html 文件的每个选项卡的特定内容吗?

最佳答案

这是 ng-include 的完美用例。根据 Documentation ,它获取、编译并包含一个外部 HTML 片段。

像这样使用它:

Javascript

$scope.templates = [
  { URL: '/path/to/file.html' },
  { URL: '/path/to/file2.html'}
]

HTML

<div ng-repeat="template in templates">
  <div ng-include="template.URL">
    <!-- Template markup goes here -->
  </div>
</div>

就是这样。只需确保 file.html 和 file2.html 存在,您就可以将您的标记直接拖到每个相应的标记中。

关于javascript - 拉入本地 html 内容的 AngularJS bootstrap-ui 选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28025392/

相关文章:

javascript - 样式更改后悬停禁用 : important doesn't work

html - 在彼此内部创建嵌套的 div 容器并更改它们的颜色

javascript - ng-model 绑定(bind)不会更新同一对象上的另一个 ng-model

javascript - 何时保证 ng-repeat 中的图像尺寸在 DOM 中可用?

javascript - 为什么我的数据选择器有副作用?

javascript - 带有 JSON 数组的 jQuery 'each' 循环

html - 如何在没有背景图像的情况下使用 CSS 3 模糊部分下方的 div?

javascript - 在指令中使用 templateUrl 时,element.find() 不起作用

javascript - 使用 jQuery 更新 DOM 元素

javascript - 如何获取插槽的文本内容?