Search code examples
javascriptangularjsangularjs-ng-repeat

How to get ng-repeat item count in angular js 1?


What i want to know is how can we get the ng-repeat count of items in angular js. From the code below I want to get the count of skill becuase i want to put a limit to it. If skill count > 5 limit skill to only 5 . Because i dont want to show all skill , just 5 items.

 <span class="label label-default bg-warning" style="margin-left: 5px"
       ng-repeat="skill in job.skills">{$ skill$} </span>

Solution

  • You can simply access using array.length. However if you are sure that you want to show only 5 items you can just hardcode 5,

    ng-repeat="skill in job.skills | limitTo:5"