ngRepeat中的静态列表项

时间:2014-07-21 14:53:47

标签: angularjs angularjs-directive angularjs-ng-repeat

所以,

我使用ngRepeat渲染基本列表,但需要第一个<li>是静态内容,而不是从数据数组生成:

e.g。

<ul ng-repeat="item in items">
  <li>This is text from the template and will always be the same.</li>
  <li>{{item}}</li>
</ul>

我也考虑过使用ng-repeat-start,但却无法找到解决方案。

1 个答案:

答案 0 :(得分:7)

一个常见的误解是人们想在父元素上使用ng-repeat,而实际上你是在重复的实际元素上使用它。

您只需将其更改为:

<ul>
  <li>This is text from the template and will always be the same.</li>
  <li  ng-repeat="item in items">{{item}}</li>
</ul>