Angularjs:ng-repeat,在ng-repeat中放置一个'divivider'来分隔最近加载的数据

时间:2013-02-07 20:32:48

标签: angularjs

当页面加载时,向用户呈现一组产品,然后如果他/她点击按钮,则获取更多产品并将其附加到列表中。我试图找到一种Angular方式来放置一行来分隔已经从最近附加的产品中加载的产品。我不想直接操作DOM而且我不能将空行推送到产品数组,因为数组的长度是在其他地方使用的。

我怎么能这样做?

Here is a basic Bin

2 个答案:

答案 0 :(得分:13)

如果您不想在最后一项之后使用分隔符,请使用:

<... ng-repeat="...">
   <hr ng-show="!$last" />
   ...
</...>

$last is true if the repeated element is last in the iterator.

答案 1 :(得分:1)

我认为你需要在另一个$ scope(array)属性中自己跟踪这个。在ng-repeat循环中,检查$ index是否在此数组中。如果是这样,请添加/显示&lt; hr&gt;。

<... ng-repeat="...">
   <span ng-show="showHr($index)"><hr></span>
   ...
</...>

当您想要显示&lt; hr&gt;时,函数showHr()应返回true

您也可以使用ng-switch代替ng-show。