AngularJS For Loop with Numbers & Ranges

后端 未结 24 3401
抹茶落季
抹茶落季 2020-11-22 13:40

Angular does provide some support for a for loop using numbers within its HTML directives:

do something <
24条回答
  •  借酒劲吻你
    2020-11-22 14:26

    A short way of doing this would be to use Underscore.js's _.range() method. :)

    http://underscorejs.org/#range

    // declare in your controller or wrap _.range in a function that returns a dynamic range.
    var range = _.range(1, 11);
    
    // val will be each number in the array not the index.
    
    {{ $index }}: {{ val }}

提交回复
热议问题