【发布时间】:2015-02-26 21:02:59
【问题描述】:
我遇到了这种情况,我需要使用 ng-repeat-start / ng-repeat-end 重复一个 HTML 代码块,但有角度抱怨:
错误:[$compile:uterdir] 未终止的属性,找到 'ng-repeat-start' 但没有找到匹配的 'ng-repeat-end'。
我找到了一种解决方法,它可能对遇到这种情况的人有用。我也想知道你的想法。它是一个错误吗?我应该避免这种方法吗?我正在使用 Angular v1.3.5,代码是这样的:
<table>
<thead>
...
<tr ng-repeat-start="a in b">
...
</tr>
...
</thead>
<tbody>
...
</tbody>
<thead>
...
<tr ng-repeat-end>
...
</tr>
...
</thead>
</table>
问题似乎是 ng-repeat-end 不在同一个 HTML 标记块内(这里是第一个 thead ng-repeat-start 在里面)。
我找到了使用以下代码的解决方法:
<table>
<thead>
...
</thead>
<thead ng-repeat-start="a in b">
<tr>
...
</tr>
...
</thead>
<tbody>
...
</tbody>
<thead>
...
</thead>
<thead ng-repeat-end>
<tr>
...
</tr>
...
</thead>
</table>
这样我将ng-repeat-start 和ng-repeat-end 放在同一个标签table 中。
【问题讨论】:
-
确切地说,ng-repeat-start 和 ng-repeat-end 必须是同级
-
这里是文档:docs.angularjs.org/api/ng/service/$compile#-multielement-。没有明确说明节点必须是兄弟节点,但
compiler will collect DOM nodes between nodes with the attributes directive-name-start and directive-name-end可能暗示了这一点
标签: angularjs angularjs-ng-repeat