Created
March 4, 2015 00:15
-
-
Save CodeVachon/db629606a4ad31af212b to your computer and use it in GitHub Desktop.
AngularJS $resource .get modify data
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
// | |
// 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