Attempting to retrieve data from a promise within a JSON object for the first time has presented me with a challenging task.
The typical approach looks something like this:
Service JS
app.factory("dataService", ["$http",
function ($http) {
function getData(id) {
return $http.get('endpoint', id)
.then(function (response) {
return response.data
});
}
return {
getData: getData
}
}])
Controller JS
$scope.data = {}
dataService.getData($routeParams.id)
.then (function (res) {
$scope.data = res
});
This method works well and satisfies everyone involved.
Now, I am attempting to assign data within an object.
Controller JS
angular.forEach($scope.properties, function (item) {
$scope.data.properties.push({
order: item.number,
name: item.name,
value: item.value,
items: $scope.getProp(item.id)
})
});
$scope.getProp = function (id) {
return dataService.single(id)
.then (function (res) {return res});
};
Service JS
function single(id) {
return $http.get('endpoint' + "/" + id)
.then(function (response) {
return response.data
})
}
Now, I am encountering a JSON object with a promise and $$state inside.
I comprehend the complexity of this issue, but solving it exceeds my current knowledge. Can anybody offer assistance in resolving this challenge?