Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

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 up 5 times assuming $scope.number equal to 5 in addition incrementing the number so each list item increments like 1, 2, 3, 4, 5

Desired result:

<ul>

<li><span>1</span></li>

<li><span>2</span></li>

<li><span>3</span></li>

<li><span>4</span></li>

<li><span>5</span></li>

</ul>

1 Answer

0 votes
by (106k points)

Yes, the newer versions of Angular 1.x allows you to define ng-repeat number of times instead of always having to iterate over an array without a function. 

See the code below:-

<div ng-repeat="x in [].constructor(number) track by $index">

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...