Skip to content

Instantly share code, notes, and snippets.

@DavidFrahm
Created August 12, 2013 22:55
Show Gist options
  • Save DavidFrahm/6216122 to your computer and use it in GitHub Desktop.
Save DavidFrahm/6216122 to your computer and use it in GitHub Desktop.
Default $resource service does not have a PUT/update method on the class. This might be because it does not expect to need to PUT without first doing a GET (it appears to be intended for 100% RESTful use), although I'm not sure if the returned instance has PUT or not. If that isn't true, then maybe they just figured POST could do both new/create…
/*
* Create a $resource with a PUT (without a GET first)
*/
angular.module('whateverService', ['ngResource'])
.factory('Whatever', function($resource) {
return $resource(getApiDomain() + '/api/whatever/', {}, {
'update': {
method: 'PUT',
isArray: false
}
});
});
/*
* Usage, i.e., in a controller
*/
Login.update(registerInput,
function success(response) {
log('success response: ' + angular.toJson(response));
$scope.registerResult = response;
}, function error(response) {
// TODO: Can we get others? status, headers, config
$scope.logAjaxError(response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment