角重复<跨度> n次跨度、LT、GT

2023-09-13 02:57:42 作者:半夏的溫柔

我有一个包含一个int属性的JSON对象 X ,我想重复以下code x次

I have a JSON object that contains an int property x, I would like to repeat following code x times

<span class="glyphicon glyphicon-star"/>

纳克重复似乎并不被表示为它的工作与收藏。结果任何建议(角新手)

ng-repeat does not seem to be indicated as it's working with collection. Any suggestion (angular newbie)

推荐答案

我会使用自定义与 NG-重复过滤

HTML

<div ng-app='myApp' ng-controller="Main">
    <li ng-repeat="n in [] | range:20">
      <span class="glyphicon glyphicon-star" >{{n}}</span>
    </li>
</div>

过滤器

app.filter('range', function() {
  return function(val, range) {
    range = parseInt(range);
    for (var i=0; i<range; i++)
      val.push(i);
    return val;
  };
});

演示 小提琴