0

I am trying to add dynamic headers to a $resource like so:

angular.module('app')
 .factory('API', function ($resource, API_URL) {
  return {
   event: function(userId){
    return $resource(API_URL + '/event/:id', {
      id: '@id'
    }, {
      get: {
        method: 'GET',
        headers: {
          'service': 'API',
          'userId': userId
        }
      },
      save: {
        url: API_URL + '/event/:id/accept',
        method: 'PUT',
        headers: {
          'service': 'API',
          'userId': userId
        }
      }
    })
  }
 };
});

Using this allows me to pass in headers which works fine when using the get.

When I want to save a object this just returns undefined:

var event = new Muse.event('jonro')(object);

Could someone please help explain why I cant use $resource in this way.

Thanks

robinsio
  • 93
  • 6

2 Answers2

0

'save' uses POST verb usually ($resource)

How do you call the save method? From the reference:

non-GET "class" actions: Resource.action([parameters], postData, [success], [error])

What does the Developer Tools says if you look your requests?

Mat
  • 2,156
  • 2
  • 16
  • 29
0

Fixed using this method for updates:

API.event('jonro').save({id: $stateParams.id}, object)
robinsio
  • 93
  • 6