Znowman Znowman - 1 month ago 18
AngularJS Question

Limit array, angular

Trying to limit the output from an array. list is the array in the data object.

<tr ng-repeat="item in data.list" ng-if=""><td>{{item.data.attribute}}</td></tr>


Is it possible to do with ng-repeat?

Answer

First thing remove ng-if. Then use limitTo filter provided by angular out of the box.

ng-repeat="item in data.list | limitTo: 4 as filtered"

You could use the same filter inside controller as well.

var limit = 5;
$scope.filteredData = $filter('limitTo')($scope.data.list)(limit);
Comments