Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@CodeVachon
Created March 4, 2015 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeVachon/db629606a4ad31af212b to your computer and use it in GitHub Desktop.
Save CodeVachon/db629606a4ad31af212b to your computer and use it in GitHub Desktop.
AngularJS $resource .get modify data
//
// Note that Articles is a $resource pointing to a express RESTful API
//
angular.module('App')
.controller('ArticlesEditController', ["$scope", "$routeParams", "$location", "Articles",
function($scope, $routeParams, $location, Articles) {
$scope.article = Articles.get({id: $routeParams.id},function(_data) {
_data.publish_date = new Date(_data.publish_date);
});
$scope.saveArticle = function(article) {
Articles.update({id: article._id}, article, function success(_data) {
$location.path("/articles/" + article._id);
}, function error(_data) {
console.log(_data.data.validationerrors);
});
}
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment