angularjs - 标签内容中的 angular-ui 标签加载模板

标签 angularjs angular-ui

我正在使用此 Controller 在 angular-ui 中使用选项卡:

$scope.panes = [
    { title:"Home",      content:"home" , active: true},
    { title:"Settings",  content:"settings"},
    { title:"View",      content:"view"}
];
这在 html 文件中:
<tabs>
    <pane
      active="pane.active"
      heading="{{pane.title}}"
      ng-repeat="pane in panes"
    >
      {{pane.content}}
    </pane>
  </tabs>
但我想将内容设置为模板我该怎么做,我尝试在此 plunker 中设置 ng-include 代码,但没有用。
提前致谢。
更新:
如果您找到此解决方案并且您没有使用 angular-bootstrap v0.12,则需要将代码更新为 the new syntax of v0.13像这样:
<tabset>
    <tab
      active="pane.active"
      heading="{{pane.title}}"
      ng-repeat="pane in panes"
    >
      <div ng-include="pane.content"></div>
    </tab>
  </tabset>
我已经更新了 plunker具有 angular-bootstrap v0.13 的语法。

最佳答案

只需添加 ng-include 作为 Pane 的 child

<tabs>
    <pane active="pane.active"
          heading="{{pane.title}}"
          ng-repeat="pane in panes">
        <div ng-include="pane.content"></div>
    </pane>
</tabs>

这样做的原因是当您使用 时,作用域变量 Pane 尚不可用。 ng-include 在与 相同的元素中ng-repeat 创建 Pane 变量。

这是因为 的优先级值ng-include 是 0(默认),而 ng-repeat 的优先级是 1000,所以执行顺序是:
  • ng-包括
  • ng-repeat

  • directive docs

    关于angularjs - 标签内容中的 angular-ui 标签加载模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14896298/

    相关文章:

    javascript - 语法错误: Unexpected token u

    javascript - Grunt usemin 任务在缩小 Angular 文件时无法处理嵌套文件

    javascript - 如何将 Angular 与 HTML5 地理定位原生 API 结合使用?

    javascript - Angular 用户界面选择 : Fetch data from remote service

    javascript - Bootstrap 日期选择器格式不适用于初始化

    javascript - 仅搜索 ui.bootstrap typeahead 中的特定字段

    javascript - 为什么 Node js res.send 不起作用?

    javascript - 如何从列表中获取选定的值

    javascript - AngularJS $http.get() 在 Chrome 中最多需要 10-20 秒,在 Firefox 中运行良好

    angularjs - 如何判断在 Angular-UI 中选择了哪个 Bootstrap 选项卡