ng-repeat for loop
ng-repeat doesn't have support for numeric iterators, but we can add a range filter a la ruby:
module.filter 'toRange', ->
(input) ->
switch (input.length)
when 1
[lowBound, highBound] = [0, +input[0] - 1]
when 2
[lowBound, highBound] = [+input[0], +input[1]]
i = lowBound
result = []
while i <= highBound
result.push i
i++
result
Now we can iterate. 5 times:
div ng-repeat="i in [5] | toRange" {{i}}
From 1 to 3:
div ng-repeat="i in [1, 3] | toRange" {{i}}
Written by Gleb Mazovetskiy
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Angularjs
Authors
Related Tags
#angularjs
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#