Lets say I have a factory called 'Stuff'.
app.factory('Stuff', function($resource) {
return $resource('api/v1/stuff/', {}, {
getThings: {
method: 'GET',
params: {id: '@id'},
url: 'api/v1/things/:id',
isArray: true
}
});
});
In this factory I have a custom getThings function.
In my controller, if I do this:
$scope.stuffs = Stuff.query();
$scope.things = Stuff.getThings({id: $scope.stuffs[0].id});
It works, and $scope.things is what I want.
But if I do this:
$scope.stuffs = Stuff.query();
$scope.things = $scope.stuffs[0].$getThings();
I get an error in angular-resource. The ajax call happens to the correct url and I get correct data back but getThings errors out immediatly after getting data, and the only thing left in $scope.things is what looks like a promise:
Object {then: function, catch: function, finally: function}
The error in JS console is:
TypeError: undefined is not a function
at http://dev.blah.com/assets/angular-resource/angular-resource.js?body=1:558:27
at forEach (http://dev.blah.com/assets/angular/angular.js?body=1:326:18)
at $http.then.value.$resolved (http://dev.blah.com/assets/angular-resource/angular-resource.js?body=1:556:17)
at wrappedCallback (http://dev.blah.com/assets/angular/angular.js?body=1:11574:81)
at wrappedCallback (http://dev.blah.com/assets/angular/angular.js?body=1:11574:81)
at http://dev.blah.com/assets/angular/angular.js?body=1:11660:26
at Scope.$eval (http://dev.blah.com/assets/angular/angular.js?body=1:12703:28)
at Scope.$digest (http://dev.blah.com/assets/angular/angular.js?body=1:12515:31)
at Scope.$apply (http://dev.blah.com/assets/angular/angular.js?body=1:12807:24)
at done (http://dev.blah.com/assets/angular/angular.js?body=1:8380:45)
I can't figure out why this isn't working.