restangular icon indicating copy to clipboard operation
restangular copied to clipboard

Using extendModel with Configurer to overwrite a Restangularized object's .post() method (app debug mode)

Open lstone opened this issue 10 years ago • 2 comments

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!

lstone avatar Dec 03 '14 03:12 lstone

In order to debug, please use request/response interceptors as described in docs.

grabbou avatar Feb 23 '15 07:02 grabbou

@lstone Can you provide an example like @grabbou requested?

daviesgeek avatar Jun 18 '16 00:06 daviesgeek