"Duplicates in a repeater are not allowed" on ng-repeat
Your JSON is invalid and should be :
{
"entries": [{
"id": 2081,
"name": "BM",
"niceName": "bodmas"
}, {
"id": 8029,
"name": "Mas",
"niceName": "Masm"
}],
"count": 2
}
Also, make sure you are accessing the document at the right level, use :
$http.get('https://myServiceURL').success(function(data){
$scope.entries = data.entries;
});
Then, it should work. See this JSBin.
If I may add an additional reason as to why this can occur...
If you are doing this with a JS object [] or {}
and you are passing it in to a directive like this
<my-directive my-attribute="{{ myObject }}"></my-directive>
Inside the directive you must turn myObject back into an object by doing this
...
controller: function( $scope ){
$scope.links = $scope.$eval( $scope.myObject );
....
Then the HTML and ng-repeat will work
...
<span class="" ng-repeat="link in links">
...
ngRepeat does not know how to repeat over a single string.
Here is what the object would look like before $scope.$eval
"[{ hello: 'you' }]"
and after $scope.$eval()
[{ hello: 'you' }] an actual object to repeat over.
The error kind of makes a reference that it cannot repeat of a string. Here is the error that I got.
Error: [ngRepeat:dupes] http://errors.angularjs.org/1.3.0-beta.8/ngRepeat/dupes?p0=link%20in%20links&p1=string%3Al
It looks like you have a problem with the structure of the data in your scope. Your example JSON shows an object with an entries
property and a count
property. You then put that whole object in your scope as entries
. This means you'd need to access the entries as entries.entries
, with the count in entries.count
. Perhaps this controller is closer to what you wanted:
myApp.controller("MyController", ['$scope', '$http', '$log', function($scope, $http, $log){
...
$http.get('https://myServiceURL').success(function(data){
$scope.entries = data.entries;
$scope.count = data.count;
});
}]);
Add track by $index
to your ng repeat so instead of:
<option ng-repeat="entry in entries" value="{{entry.name}}">{{entry.name}}</option>
Try:
<option ng-repeat="entry in entries track by $index" value="{{entry.name}}">{{entry.name}}</option>
There's further information about this in the documentation for this error message:
Occurs if there are duplicate keys in an ngRepeat expression. Duplicate keys are banned because AngularJS uses keys to associate DOM nodes with items.
By default, collections are keyed by reference which is desirable for most common models but can be problematic for primitive types that are interned (share references).