Skip to content

Instantly share code, notes, and snippets.

@YanTheFawn
Created June 24, 2014 18:43
Show Gist options
  • Save YanTheFawn/64fa7f9cfb51de25a50d to your computer and use it in GitHub Desktop.
Save YanTheFawn/64fa7f9cfb51de25a50d to your computer and use it in GitHub Desktop.
var bulletinApp = angular.module('bulletinApp', ['ngResource']);
bulletinApp.controller('PostsCtrl', ['$scope', 'Post', function($scope, Post){
this.heading = 'Bulletin Board';
this.posts = Post.query();
var PostsCtrl = this;
this.create = function(){
Post.save($scope.newPost, function(resource){
PostsCtrl.posts.push(resource);
PostsCtrl.newPost = {};
}, function(response){
console.log('Error ' + response.status);
});
}
}]);
bulletinApp.factory('Post', ['$resource', function($resource){
return $resource('/posts.json', {posts: {title: '@title'}}, {method: 'GET', isArray: false});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment