0

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>'},  
Angular_Newbie
  • 415
  • 1
  • 9
  • 25

2 Answers2

2

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.

Community
  • 1
  • 1
ajmajmajma
  • 13,712
  • 24
  • 79
  • 133
0

Angular provide the unique filter:

<div ng-repeat="item in result | unique:'_id'">
    //Body here
</div>
Alexandru Olaru
  • 6,842
  • 6
  • 27
  • 53