I am facing an issue in my code where I have a function nested inside a directive that fetches query results successfully. However, I am struggling to store these results in a factory and then pass them to a controller.
Below is the code snippet of the directive:
scope.getVersions = function(release) {
if (angular.isUndefined(release)) return;
musicInfoService.getReleaseVersions(release.id)
.success(function(data) {
dataService = data.versions;
console.log(dataService);
});
};
After getting the results, I attempt to save them in a factory:
app.factory('dataService', [function(){
return { items: [] };
}]);
Then, I call the factory in a controller:
function VersionController($scope, dataService) {
$scope.versions = dataService.items;
console.log($scope.versions);
}
However, both items and $scope.versions are returning as empty arrays. Am I missing something here?