【问题标题】:why angularjs ng-include doesn't work like this为什么 angularjs ng-include 不能这样工作
【发布时间】:2015-09-25 04:49:08
【问题描述】:

我想使用 ng-template 来迭代我的 args,这有助于构建缩进菜单内容。但 ng-include 对我不起作用。我已经添加了报价。

这是一个简单的示例,http://codepen.io/elvis-macak/pen/meropX

body(ng-app="app",ng-controller="MainController")

  script(type='text/ng-template', id="data-list.html")
    span {{key}}
    span {{value}}

  div
    div(ng-repeat="data in datas")
      h3 {{data.date }}
      ul      
        li(ng-repeat="(key, value) in data")
          span {{key}}
          span {{value}}
      ul
        li(ng-include, src="data-list.html", ng-repeat="(key, value) in data")

无法打印出里面的脚本内容。

我不知道为什么,有人可以帮助我吗?

【问题讨论】:

    标签: javascript angularjs angularjs-ng-include angularjs-ng-template


    【解决方案1】:

    我不能 100% 确定您在问什么,但我的理解是您希望在 ng-repeat 中使用 ng-include。我不使用 Jade,但从您的示例中查看一些已编译的 HTML:

    <li ng-include="ng-include" src="'data-list.html'" ng-repeat="(key, value) in data"></li>
    

    您对 ng-include 的论点不正确。它应该看起来像:

    <li ng-include src="'data-list.html'" ng-repeat="(key, value) in data"></li>
    

    这似乎有效。但是,在 ng-repeat 中使用 ng-include 时要小心,因为它不利于性能。随着您发展到更复杂的需求(例如在 ng-repeats 中使用复杂的视图),您可能想要使用指令,这是操纵 DOM 的角度方式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-30
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      • 2017-12-05
      • 2015-02-20
      • 1970-01-01
      相关资源
      最近更新 更多