为什么angularjs的ng-include不能像这样工作?

why angularjs ng-include doesn't work like this

本文关键字:像这样 工作 不能 ng-include angularjs 为什么      更新时间:2023-09-26

我想使用ng-template来迭代我的参数,这可以帮助构建缩进菜单内容。但是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")

它不能打印出里面的脚本内容。

我不知道为什么,有人能帮帮我吗?

我不是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-repeat中使用复杂的视图),您可能会想要使用指令,这是操纵DOM的角方式。