Hello I am having problems of indexes when trying to delete from an array.
<i class="icon ion-ios-checkmark-outline" ng-click="addToHistory(task.info, task.measured, task.total, task.done, task.id)" ></i>
{{task.info}}
$scope.addToHistory = function(title, measured, total, done, id) {
var index = $scope.tasksCollection.indexOf($scope.tasksCollection[id]);
$scope.tasksCollection.splice(index, 1);
}
the Above works, but when I try to delete the first item, and go for the second one, the third gets deleted instead of the second one. I know is a problem of indexes, but I dont have ideas on how to solve it.
To recap I have:
- Item1 (index 0)
- Item2 (index 1)
- Item3 (index 2)
when I delete the first one I get
- Item2 (index 0)
- Item3 (index 1)
and when I try to delete Item2, the index I get back is 1, so Item3 gets deleted.