restangular
restangular copied to clipboard
Using extendModel with Configurer to overwrite a Restangularized object's .post() method (app debug mode)
I want to override the .post() method of a Restangularized object so that I can write a debug mode for the app I'm working on. My reading led me to believe this would work.
forms-service.coffee
restAngular = Restangular.withConfig (Configurer) ->
# config here
Configurer.setBaseUrl('/api/v1')
Configurer.extendModel 'forms', (model) -> # TODO: if debug mode
model.post = ->
console.log 'post() method override!'
return model
_formService = restAngular.all('forms')
Given the above extendModel I would expect the console.log 'post() method override!' to fire, but instead the original post() method fires off a POST to /api/v1. form-controller.coffee
$scope.form.post().then (response) ->
$log.log response
How can I overwrite the post() method of a Restangularized object returned from the server? Thanks!
In order to debug, please use request/response interceptors as described in docs.
@lstone Can you provide an example like @grabbou requested?