Is there a way to ng-repeat
a defined number of times instead of always having to iterate over an array?
For example, below I want the list item to show
simple way:
public defaultCompetences: Array<number> = [1, 2, 3];
in the component/controller and then:
<div ng-repeat="i in $ctrl.defaultCompetences track by $index">
This code is from my typescript project but could be rearranged to pure javascript
I wanted to keep my html very minimal, so defined a small filter that creates the array [0,1,2,...] as others have done:
angular.module('awesomeApp')
.filter('range', function(){
return function(n) {
var res = [];
for (var i = 0; i < n; i++) {
res.push(i);
}
return res;
};
});
After that, on the view is possible to use like this:
<ul>
<li ng-repeat="i in 5 | range">
{{i+1}} <!-- the array will range from 0 to 4 -->
</li>
</ul>