Shaheryar Mahmood
Shaheryar Mahmood

Reputation: 63

AngularJS Error: [ngRepeat:dupes]

I am getting JSON data with PHP but on ng-repeat getting error:

[ngRepeat:dupes] Duplicates in repeater are not allowed

I tried to track by $index but every time browser crashing with track by $index, working perfectly in localhost but on Web Hosting getting the above error.

Any Solution?

JSON data:

{
  id : "1",
  title : "Title1",
  src : "Source1"
},
{
  id : "2",
  title : "Title2",
  src : "Source2"
}

Upvotes: 4

Views: 139

Answers (1)

Shashank Agrawal
Shashank Agrawal

Reputation: 25797

You can try something like this. Define a method in your controller scope:

$scope.getIndexFunction = function($index, data) {
    // Generate a unique string so that ng-repeat can avoid error
    return $index + '' + data.toString();
};

Now, in your view:

<div ng-repeat="source in sources track by getIndexFunction($index, source)"> {{source.title}}</div>

Directive doesn't fire after changing textarea model

Upvotes: 2

Related Questions