I am trying to call an api after an initial call returns the parent objects, so that I can set some child properties. The parent objects are days and they own timeslots. So in angular I am watching the days array and then I try to fetch each day's timeslots.
However somehow restangular assigns duplicate timeslot results to different days. When I check the chrome logs I can see that the correct requests were made to the right endpoint but the results are duplicated, eg a request for tuesday's timeslots may return wednesday timeslots, so tuesday and wednesday end up having the same timeslots. Here is my code:
$scope.$watch(function() {
return vm.days;
}, function(newvalue, oldvalue) {
for (var c = 0; c < newvalue.length; c++) {
const index = c;
newvalue[index].getList("timeslots").then(function(result) {
console.log("index: " + index + ", c:" + c);
newvalue[index].timeslots = result;
}, function(response) {
console.log(response);
});
}
}, false);