Created
February 13, 2014 14:37
-
-
Save jvmvik/8976107 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* 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