When working with AngularJS, all actions for a $resource
are added as $customAction
methods to the Resource. This allows me to easily invoke them as methods on resource instances. For example:
var User = $resource('/user/:userId', {userId:'@id'});
User.get({userId:123}, function(user) {
user.abc = true;
user.$save();
});
In this case, $save
is the equivalent of the save
action and can be called directly on the user
instance.
Now, if I introduce a custom action like the following, it will create a $attributes
method on every instance of the user
:
var User = $resource('/user/:userId', {userId:'@id'}, {
attributes: { method: 'GET', url: '/user/:userId/attributes', isArray: true }
});
However, when attempting to use this newly defined method, an error occurs stating
Object #<Resource> has no method 'push'
:
User.get({userId:123}, function(user) {
var attrs = user.$attributes(); // error
// ...
});
Could it be that I misunderstood the concept of custom actions?