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

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

    This is only a slight variation on the accepted answer, but you don't really need to create a new function. Only to import 'Array' in the scope:

    • {{$index+1}}
    var app = angular.module('myapp',[]);
    app.controller('ctrlParent',function($scope){
        $scope.myNumber = 5;
        $scope.counter = Array;
    });
    

    See this fiddle for a live example.

提交回复
热议问题