UR13X UR13X - 3 months ago 17
AngularJS Question

Iteration ng-repeat only X times in AngularJs

How can I use ng-repeat like for in Javascript?

example:

<div ng-repeat="4">Text</div>


I want to iterate with ng-repeat 4 times but how can I do it?

mpm mpm
Answer

in the html :

<div ng-repeat="t in getTimes(4)">text</div>

and in the controller :

$scope.getTimes=function(n){
     return new Array(n);
};

http://plnkr.co/edit/j5kNLY4Xr43CzcjM1gkj

EDIT :

with angularjs > 1.2.x

<div ng-repeat="t in getTimes(4) track by $index">TEXT</div>