Using ng-repeat in a range
Published in
1 min readMay 30, 2015
Sometimes we need to repeat an element X times.
Sadly, AngularJS doesn’t have a native behavior for that, but we can create a simple filter to add this functionality.
'use strict';angular.module('MYAPP')
.filter('range', function() {
return function(list, total) {
total = parseInt(total, 10);
for (var i = 0; i < total; i++) {
list.push(i);
} return list;
};
});
Basic Usage:
<div ng-repeat="n in [] | range:X">
{{$index}} - This will repeat X times.
</div>