My controller code:
.controller('DashCtrl', function($scope, Files) {
$scope.getFiles = function() {
Files.test().then(function(results) {
$scope.files = results;
});
};
})
My factory code:
app.factory('Files', function($http) {
return {
test: function() {
var call = 'https://www.somesite.com';
$http({method: 'GET', url: call}).
success(function(data) {
// Do some stuff to data..
// blah blah blah
return results;
}).
error(function(data, status, headers, config) {
return;
});
}
}
});
That code throws the error:
“Cannot read property ‘then’ of undefined”
If I change the $http line to:
return $http({method: 'GET', url: call}).
Then the “data” variable gets returned and not the “results” variable.
What am I doing wrong?
So, here is how I resolved it:
.controller('DashCtrl', function($scope, Files) {
$scope.getFiles = function() {
Files.test().then(function(results) {
// Do some stuff to data..
$results = data blah blah
// blah blah blah
$scope.files = $results;
});
};
})
Factory code:
app.factory('Files', function($http) {
return {
test: function() {
var call = 'https://www.somesite.com';
return $http({method: 'GET', url: call}).
success(function(data) {
}).
error(function(data, status, headers, config) {
});
}
}
});
Thanks!