Adding PUT to default NG-Resource Actions in AngularJS

angularjs, angularjs-resource, javascript

Solution

The only simple way I can see is to create a wrapper around $resource:

module.factory('$myResource', ['$resource', function($resource){
  return function(url, paramDefaults, actions){
     var MY_ACTIONS = {
       'update':   {method:'PUT'}
     };
     actions = angular.extend({}, MY_ACTIONS , actions);
     return $resource(url, paramDefaults, actions);
  }
}]);

Problem

I am trying to add PUT to the default methods in ng-resource. So far I modified the DEFAULT_ACTIONS to: ``` var DEFAULT_ACTIONS = { 'get': {method:'GET'}, 'save': {method:'POST'}, 'update': {method:'PUT'}, 'query': {method:'GET', isArray:true}, 'remove': {method:'DELETE'}, 'delete': {method:'DELETE'} }; ``` But this feels very hacky and obviously will not persist when I update the module. Is there a way that I can add update/put to all ng-resource objects that will persist with updates?

Original source