Angular ng-repeat元素数量统计

4
<li ng-repeat="Item in Items">
        <div ng-switch="($index)==0">
            <div ng-switch-when="true">
                <a href="#"><   Previous</a>
            </div>
            <div ng-switch-when="false">
                <a href="#">{{$index}}</a>
            </div>
        </div>
    </li>

我想获得"Items"元素的数量,并在最后一个项目中显示"Next >"。
1个回答

12

像这样的东西

<li ng-repeat="Item in Items">
                <a ng-if="$first" href="#"><   Previous</a>
                <a ng-if="!$first && !$last" href="#">{{$index}}</a>
                <a ng-if="$last" href="#">Next ></a>
    </li>

要获取长度,请使用Items.length。如果有过滤器,则会变得更加复杂。请参阅此SO post


谢谢Chandermani。问题已解决。我在ng-switch中使用了$first和$last,因为我的版本无法使用ng-if。非常感谢。 - Isuru

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接