Skip to content

Instantly share code, notes, and snippets.

@jvmvik
Created February 13, 2014 14:37
Show Gist options
  • Save jvmvik/8976107 to your computer and use it in GitHub Desktop.
Save jvmvik/8976107 to your computer and use it in GitHub Desktop.
/***
* How to add a callback to AngularJS $resource.
*
* Promises enables to add success and failure callback
* after the execution of $resource method.
*/
var app = angular.module("application", ['ngResource']);
app.factory('$crud', function ($resource) {
return $resource('url', {}, {
update: { method: 'PUT' }
})
});
// Call
$crud.update($scope.data)
.$promise
.then
(
// Success
function(data)
{
$scope.status = "Success";
},
// Error
function( error )
{
$scope.status = "Error";
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment