Seamy Seamy - 1 year ago 129
Javascript Question

ng:repeat dupes. Getting duplicate data in ng-repeat

Hey so I have a problem in my angular app in regard to dup data. I have identified the problem down to an exact ng-repeat but I can't see what is wrong with it. I am getting an error saying I have duplicate data but I can't see how it happening because I have only 4 items in my database currently. I have tried different things like renaming and such but to me it looks right so I'm a little stumped as to why I am getting the error. I am thinking maybe the data is being loaded twice but not sure how? Anyways I will post the relevant code and if some angular god out there can point me on my way I'd be forever grateful.

The error message is:
angular.min.js:84 Error: [ngRepeat:dupes]


app.controller('tasksController', function ($scope, $http) {
getTask(); // Load all available tasks

function getTask() {
$'ajax/getTask.php').success(function (data) {
$scope.tasks = data;

$scope.addTask = function (task) {
$'ajax/addTask.php?task=' + task).success(function (data) {
$scope.taskInput = '';

$scope.deleteTask = function (task) {
if (confirm('Are you sure to delete this line?')) {
$'ajax/deleteTask.php?taskID=' + task).success(function (data) {

$scope.toggleStatus = function (item, status, task) {
if (status == '2') {
status = '0';
} else {
status = '2';
$'ajax/updateTask.php?taskID=' + item + '&status=' + status).success(function (data) {


<div class="task">
<label class="checkbox" ng-repeat="task in tasks track by | filter : filterTask">
ng-click="toggleStatus(task.ID,task.STATUS, task.TASK)"/>
<span ng-class="{strike:task.STATUS==2}">{{task.TASK}} [{{task.ID}}]</span>
<a ng-click="deleteTask(task.ID)" class="pull-right"><i class="glyphicon glyphicon-trash"></i></a>

Answer Source

As the link in the error message suggests, you can work around the issue using track by:

<div ng-repeat="value in [4, 4] track by $index"></div>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download