【问题标题】:Angular ng-repeat element count角度 ng-repeat 元素计数
【发布时间】:2013-12-20 13:34:16
【问题描述】:
<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>

我想获取项目的元素计数,并希望为最后一个项目显示“下一个 >”

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    类似的东西

    <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

    【讨论】:

    • 谢谢钱德曼尼。问题解决了。我在 ng-switch 中使用了 $first 和 $last,因为我不能在我的版本中使用 ng-if。非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 2015-05-25
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    相关资源
    最近更新 更多