AngularJS error: [ngRepeat: dupes]

I get JSON data with PHP, but with an ng-repeat error:

[ngRepeat:dupes] Duplicates in repeater are not allowed

I tried track by $index, but every time the browser crashes with track by $index, it works fine in localhost, but in the web hosting I get the error above.

Any solution?

JSON data:

{
  id : "1",
  title : "Title1",
  src : "Source1"
},
{
  id : "2",
  title : "Title2",
  src : "Source2"
}
+4
source share
1 answer

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

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

The directive does not work after changing the textarea model

+2
source

Source: https://habr.com/ru/post/1620966/


All Articles