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

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

    since iterating over a string it will render an item for each char:

  • {{$index}} //THIS DOESN'T ANSWER OP'S QUESTION. Read below.
  • we can use this ugly but no-code workaround using the number|n decimal places native filter.

     
  • {{$index}}
  • this way we'll have mynumber elements with no extra code. Say '0.000'.
    We use mynumber - 2 to compensate 0.
    It won't work for numbers below 3, but might be useful in some cases.

提交回复
热议问题