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

前端 未结 26 3225
刺人心
刺人心 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:44

    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:

    • {{i+1}}

提交回复
热议问题