我定义一个自定义过滤器,如:
<div class="idea item" ng-repeat="item in items" isoatom> <div class="section comment clearfix" ng-repeat="comment in item.comments | range:1:2"> .... </div> </div>
正如你所看到的,使用过滤器的ng-repeat嵌套在另一个ng-repeat中
过滤器定义如下:
myapp.filter('range',function() { return function(input,min,max) { min = parseInt(min); //Make string input int max = parseInt(max); for (var i=min; i<max; i++) input.push(i); return input; }; });
我越来越:
Error: Duplicates in a repeater are not allowed. Repeater: comment in item.comments | range:1:2 ngRepeatAction@07000
解决方案实际上描述如下:
http://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in-angularjs/
AngularJS不允许在ng-repeat指令中重复。这意味着如果你试图做以下,你会得到一个错误。
// the below will throw the error Duplicates in a repeater are not allowed. Repeater: row in [1,1,1] key: number:1 <div ng-repeat="row in [1,1]">
然而,稍微改变上述代码以定义索引以确定如下的唯一性将使其再次工作。
// this will work <div ng-repeat="row in [1,1] track by $index">