Way to ng-repeat defined number of times instead of repeating over array?

前端 未结 26 3668
刺人心
刺人心 2020-11-22 14:53

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

26条回答
  •  孤独总比滥情好
    2020-11-22 15:32

    Easiest answer: 2 lines of code

    JS (in your AngularJS controller)

    $scope.range = new Array(MAX_REPEATS); // set MAX_REPEATS to the most repetitions you will ever need in a single ng-repeat that makes use of this strategy
    

    HTML

    ...where repeatCount is the number of repetitions that should appear in this location.

提交回复
热议问题