Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ng-repeat element count

Tags:

angularjs

<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>

I want to get element count of the Items and want to show "Next >" for last item

like image 551
Isuru Avatar asked Dec 15 '22 03:12

Isuru


1 Answers

Something like this

<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>

To get the length use Items.length. It becomes more complex if there is a filter. See this SO post

like image 154
Chandermani Avatar answered Jan 20 '23 15:01

Chandermani