Rusty
Rusty

Reputation: 329

Make angular-resource ignore server response

I have a resource Post, and want to be able to mark its items as read. My server only responds with status 200. This leads to angular-resource setting my Post items to ['O', 'K'].

How do I tell angular-resource to not set my post items to the server response?

var Post = $resource('/api/post/:id/:action', {
  id: '@_id'
}, {
  read: {
    method: 'PUT',
    params: {
      action: 'read'
    }
  }
});


Post.get(function(post) {
  post.$read();
}

Upvotes: 1

Views: 279

Answers (1)

Rusty
Rusty

Reputation: 329

After reading the documentation, and skimming thru the source code I didn't find any flag for this. However when using transformResponse without returning an object (e.g. angular.noop), it seems to be working.

var Post = $resource('/api/post/:id/:action', {
  id: '@_id'
}, {
  read: {
    method: 'PUT',
    params: {
      action: 'read'
    },
    transformResponse: angular.noop
  }
});

Upvotes: 1

Related Questions