I've encountered an issue in Angular where I am trying to remove an element, but I keep receiving an Error: [ngRepeat:dupes]
after deleting an item from the list.
This is how my controller is set up:
app.controller("ListController",[function () {
this.tasks = [
{ id: 1, taskName : "Task 1", badge : 10 },
{ id: 2, taskName : "Task 2", badge : 12 },
{ id: 3, taskName : "Task 3", badge : 14 },
{ id: 4, taskName : "Task 4", badge : 15 }
];
this.remove = function(id) {
var key;
for (key in this.tasks) {
if(this.tasks[key].id === id) {
var found = true;
break;
}
}
if(found) delete this.tasks[key];
}
}]);
And here's how it is displayed in the view:
<li class="list-group-item" ng-repeat="task in ListCtrl.tasks">
<span class="badge">{{task.badge}}</span>
<button type="button" class="btn btn-xs btn-danger" ng-click="ListCtrl.remove(task.id)"><i class="glyphicon glyphicon-remove"></i></button>
{{task.taskName}}
</li>
This error message keeps popping up:
Error: [ngRepeat:dupes] http://errors.angularjs.org/1.3.13/ngRepeat/dupes?p0=task%20in%20ListCtrl.tasks&p1=undefined%3Aundefined&p2=undefined
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js:6:417
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js:233:39
at Object.fn (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js:122:63)
at l.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js:123:138)
at l.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js:126:58)
at HTMLButtonElement.<anonymous> (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js:215:36)
at HTMLButtonElement.c (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js:32:389)