Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: [ngRepeat:dupes] what does this mean?

Tags:

repeat directive outputing wine records from an api. I have a factory function to serve up the wine API which is then accessed in my controller

app.factory("Wine", function ($http){      var factory = {};       //getWines       factory.getWines = function(){        return $http.get("http://www.greatwines.9000.com")      }  } 

Controller:

    app.controller("winesCtrl", function($scope, $http, Wine){         Wine.getWines()          .success(function(wines){            $scope.wines = wines;         })         .error(function(){              alert("Error!");          });     });  VIEW:  <h2>Wine list</h2>     <div class="row margin-top-20 wine-container" ng-repeat="wine in wines">         <div class="col-sm-3">             <img src="{{wine.picture}}" class="img-responsive" />         </div>         <div class="col-sm-9">             <div class="margin-top-20">                 <span class="bold">Name: </span><span>{{wine.name}}</span>             </div>             <div>                 <span class="bold">Year: </span><span>{{wine.year}}</span>             </div>             <div>                 <span class="bold">Grapes: </span><span>{{wine.grapes}}</span>             </div>             <div>                 <span class="bold">Country: </span><span>{{wine.country}}</span>             </div>             <div>                 <span class="bold">Region: </span><span>{{wine.region}}</span>             </div>             <div>                 <span class="bold">Price: </span><span>{{wine.price}}</span>             </div>             <div>                 <span class="bold">{{wine.description}}</span>             </div>             <div class="margin-top-20">                 <a href="#/wines/{{wine.id}}" class="btn btn-default">Edit Wine</a>             </div>         </div>     </div> 

I clicked on this error and in typical "vague" angularjs fashion I get this:

Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: wine in wines, Duplicate key: string:e, Duplicate value: e 

What does this mean? wine is not the same as "wines" so why does it think it is a duplicate?

like image 860
HGB Avatar asked Oct 08 '15 14:10

HGB


People also ask

What is the standard error of the mean?

Revised on February 11, 2021. The standard error of the mean, or simply standard error, indicates how different the population mean is likely to be from a sample mean. It tells you how much the sample mean would vary if you were to repeat a study using new samples from within a single population.

What is an error code and how do I Fix It?

When a problem occurs loading a webpage, an error code and message will appear in the browser instead of the webpage. The error code and message that appears is determined by the type of error. Typically the error code consists of a 3 to 4 digit number and a brief message describing the error.

Why am I getting ng-repeat error occur?

Occurs if there are duplicate keys in an ngRepeat expression. Duplicate keys are banned because AngularJS uses keys to associate DOM nodes with items. This means that $scope.wines have some values which are duplicate. You can also refer this post : Angular ng-repeat Error "Duplicates in a repeater are not allowed."

What do error codes in my browser window mean?

The following article discusses the meaning of error codes that may appear in your browser window. When a problem occurs loading a webpage, an error code and message will appear in the browser instead of the webpage. The error code and message that appears is determined by the type of error.


2 Answers

Occurs if there are duplicate keys in an ngRepeat expression. Duplicate keys are banned because AngularJS uses keys to associate DOM nodes with items.

This means that $scope.wines have some values which are duplicate.

You can also refer this post : Angular ng-repeat Error "Duplicates in a repeater are not allowed."

like image 165
Sourabh Agrawal Avatar answered Oct 27 '22 01:10

Sourabh Agrawal


It is true that AngularJS uses keys to associate DOM nodes with items. So, you can solve by adding "track by $index".

It will look like this

ng-repeat="wine in wines track by $index"

like image 38
Y. Tiwari Avatar answered Oct 26 '22 23:10

Y. Tiwari