0

Javascript -

angular
  .module('app.somecontroller', [])
  .controller('SomeController', SomeController)

function SomeController(){
  containerInd = [0,1,2,3,4]
}

HTML -

<ul>
  <li ng-repeat='i in containerInd'>
    {{i}}
  </li>
</ul>

Far as i know ng-repeat must use object on controller itself, how about repeat like-

for(var i=0;i<n;i++)

<li ng-repeat='i to 5'>

Can angular ng-repeat do that ?

--edit--

Ah,, i got it i can do some thing like that

<li ng-repeat='(key,value) in containerList'

sory :(, my question is not clear before I have list of string on containerList and need to get the key of list inside ng-repeat

tekdungtralala
  • 261
  • 5
  • 11
  • possible duplicate of [AngularJS For Loop with Numbers & Ranges](http://stackoverflow.com/questions/11873570/angularjs-for-loop-with-numbers-ranges) – Uluk Biy Feb 19 '15 at 05:20
  • @UlukBiy Hai uluk, sory im new here and what must i do if it's like duplicate ? – tekdungtralala Feb 19 '15 at 05:22
  • Well you may delete it but there are answers below so if those are helpful accept or upvote (and of course if necessary downvote) them. However keep the question for future reference to users who comes here by search engine or by question title. For "duplicate" and other this site related questions you can use [`duplicate-questions` meta tag](http://meta.stackoverflow.com/questions/tagged/duplicate-questions) and ["duplicate+question" help](http://stackoverflow.com/help/search?q=%22duplicate+question%22) sites. Welcome! – Uluk Biy Feb 19 '15 at 06:27

2 Answers2

0

Yes you can, but you have to find a way to attach it to a $scope, in your case the $rootScope

var app = angular.module('plunker', []);

app.run(function($rootScope){
  $rootScope.list = [0,1,2,3,4];
})

Example

yangli-io
  • 16,760
  • 8
  • 37
  • 47
0
Simply use Filters:-

    <li ng-repeat="n in [] | range:10">
    {{n}}
    </li>

var myApp = angular.module('myApp', []);
myApp.filter('range', function() {
  return function(input, total) {
    total = parseInt(total);
    for (var i=0; i<total; i++)
      input.push(i);
    return input;
  };
});

Fiddle

squiroid
  • 13,809
  • 6
  • 47
  • 67