I've got a problem with assigning some properties to $scope.milestones
object in my code.
MilestonesService.query({ gameId: $stateParams.gameId }, function(data) {
$scope.milestones = data;
for(var i in $scope.milestones) {
if($scope.milestones[i]._id) {
$http.get('/admin/tasks/byMilestone/' + $scope.milestones[i]._id).success(function(tasks) {
$scope.milestones[i].tasks = tasks.length;
$scope.milestones[i].tasksSolved = tasks.length;
tasks.forEach(function(task) {
if(!task.evaluate.accepted) $scope.milestones[i].tasksSolved -= 1;
});
}).error(function(err) {
console.log(err);
});
}
}
});
It throws an error to console: Cannot assign to read only property 'tasks' of true, problem is on lines with $scope.milestones[i].tasks
and $scope.milestones[i].tasksSolved
. Why I can't assign value and extend each $scope.milestones
object?
Edit: data
0: Resource
$$hashKey: "01J"
__v: 0
_id: "5664b44b4a502abc27613d7b"
assignedToGame: "5664a04eeff8972c24651371"
date: "2015-12-19T00:00:00.000Z"
description: "Haha"
solved: false
title: "Milestones works"
__proto__: Resource
$promise: Object
$resolved: true
length: 1
__proto__: Array[0]
$scope.milestones[i]:
$$hashKey: "01J"
__v: 0
_id: "5664b44b4a502abc27613d7b"
assignedToGame: "5664a04eeff8972c24651371"
date: "2015-12-19T00:00:00.000Z"
description: "Haha"
solved: false
title: "Milestones works"
__proto__: Resource