Reputation: 417
Having trouble with duplicate keys in NG-Grid. Search for Tim then click on ng grid column in gridOptions1 to see duplicates in gridOptions2. Any ideas?
Here's plnkr
$scope.gridColumnDefs2 = [
{displayName:'Phone', cellTemplate:
'<div data-ng-repeat="(key, ngClickResult) in ngClickResults track by $index">{{ngClickResult.phone}}</div>'},
Upvotes: 0
Views: 918
Reputation: 14216
I like to use track by
to solve this, unless there is some reason you should not, try track by $index
- that usually does the trick!
<div data-ng-repeat="(key, ngClickResult) in ngClickResults track by $index">
Or if you're actually trying to remove the items from the data you can filter , something like this from this answer here - AngularJs Remove duplicate elements in ng-repeat
Although If you use this second method, unless you are really stuck I would recommend trying to modify the data coming in before it hits the repeat - maybe on the server if you have access to that.
Upvotes: 2
Reputation: 7092
Angular provide the unique
filter:
<div ng-repeat="item in result | unique:'_id'">
//Body here
</div>
Upvotes: 0