How to add a custom method to a restatular service?

I have a disabled relay service to which I would like to add a special method. Apparently, the only methods returned by default in the collection are getList , one and post . I would like to do Locations.getLongLat()

I tried adding the following to my service with no luck (the method is not bound to an object) and I just get undefined is not an object in response.

 angular.module('myApp') .factory('Locations', function (Restangular) { return Restangular.withConfig(function (RestangularConfigurer) { RestangularConfigurer.addElementTransformer('api/v1/locations', true, function (location) { location.addRestangularMethod('getLongLat', 'get', 'longlat'); return location; }); }).service('api/v1/locations'); }) 

Does anyone have any idea?

+7
angularjs angularjs-service restangular
source share
1 answer

Just in case, someone wondered how I decided this - user methods along with the service are not actually supported in the main Restangular branch. The call service simply overrides the collection and any user methods used before, with default settings.

To solve the problem, I redefined the toService function to support custom methods.

+3
source share

All Articles