How does on go about getting a variable that is the result of a factory in Angular? I keep getting undefined when i try to get results from my factory.
For instance in my factory i have
angular.module('MyApp.services', [])
.factory('ReportService', ['$http', '$window', '$upload', 'AuthService', function ($http, $window, $upload, AuthService) {
return {
findAll: function (criteria) {
criteria = criteria || [];
return $http.get(BASE_URL + '/ajax.php?action=reports.all&' + criteria.join('&'))
},
getAll: function (criteria){
return $http.get(BASE_URL + '/ajax.php?action=reports.all&' + criteria.join('&'))
.success(function(data, status) {
return data;
});
} }
}])
Then in my controller
controller('MyController', ['$scope', '$compile', 'CartoDBService', 'ReportService', 'toaster', '$modal', '$rootScope', function ($scope, $compile, ReportService, toaster, $modal, $rootScope) {
var reportSearchParams = ['graded=on'];
var cat = ReportService.findAll(reportSearchParams);
cat.then(function(data) {
$scope.students = data.data;//don't forget "this" in the service
});
console.log($scope.students);//returns unidentified
}