Skip to content

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

@lstone

Description

@lstone

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions