0 votes
1 view
in Web Technology by (47.8k points)

I am defining a custom filter like so:

<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>

As you can see the ng-repeat where the filter is being used is nested within another ng-repeat

The filter is defined like this:

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; 

   }; 

});

I'm getting:

Error: Duplicates in a repeater are not allowed. Repeater: comment in item.comments | range:1:2 [email protected]https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/an

1 Answer

0 votes
by (107k points)

The error you are getting because AngularJS does not allow duplicates in an ng-repeat directive. This means if you are trying to do the following, you will get an error.

<div ng-repeat="row in [1,1,1]">

However, you can get rid of that error by changing the above code slightly to define an index to determine uniqueness as below will get it working again.

<div ng-repeat="row in [1,1,1] track by $index">

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...