Reputation: 2662
I'm using a Decoupled Restangular service for consuming my API:
// Declare factory
module.factory('Users', function(Restangular) {
return Restangular.service('users');
});
I'd like to call a custom method on my resource: /users/active
The documentation says I can do it like so:
// GET /users/active
Restangular.all("users").customGET("active")
However, I'd like to use the service I created before, rather than redeclaring a restangular resource 'users', which wouldn't be completely "DRY".
I'd like to do something like:
Users.customGET("active")
But I get an error TypeError: Users.customGET is not a function.
Upvotes: 1
Views: 665
Reputation: 543
You can do that using the with config try something like this
return Restangular.withConfig(function(config){
config.addElementTransformer('realm',true,function(worker){
worker.addRestangularMethod('getActive','get');
return worker;
});
}).service('users');
Upvotes: 2