Angular 2: How to write a for loop, not a foreach loop

后端 未结 9 520
甜味超标
甜味超标 2020-12-05 09:41

Using Angular 2, I want to duplicate a line in a template multiple times. Iterating over an object is easy, *ngFor="let object of objects". However, I

9条回答
  •  醉酒成梦
    2020-12-05 10:09

    you can use _.range([optional] start, end). It creates a new Minified list containing an interval of numbers from start (inclusive) until the end (exclusive). Here I am using lodash.js ._range() method.

    Example:

    CODE

    var dayOfMonth = _.range(1,32);  // It creates a new list from 1 to 31.
    

    //HTML Now, you can use it in For loop

    {{day}}

提交回复
热议问题