Within my controller, I have a function that initializes two empty objects, $scope.orderHistory and $scope.results. The function, named getHistory, takes in parameters max and offset.
$scope.orderHistory = {};
$scope.results = {};
var getHistory = function (max, offset)
{
//perform some operations
$scope.orderHistory = data.entities;
angular.forEach($scope.orderHistory, function(value)
{
$scope.results = getResults(value.id);
console.log($scope.results);
});
}
var getResults = function(id)
{
api.getHistoryData(id)
.then(function(results)
{
return results.data;
});
};
The issue I am facing is that the getResults function does not seem to properly return the data and store it in $scope.results within the getHistory function.
While inside the .then part of the getResults function, when I use console.log(results.data), I can see the data. Can someone assist me in understanding why it is failing to return the results even though they exist, and suggest a solution to resolve this problem?