Skip to content

Instantly share code, notes, and snippets.

@jdx
Last active October 16, 2015 21:11
Show Gist options
  • Save jdx/f69225637e7c8f9eca65 to your computer and use it in GitHub Desktop.
Save jdx/f69225637e7c8f9eca65 to your computer and use it in GitHub Desktop.
'use strict';
angular.module('app', []);
angular.module('app')
.controller('TodoCtrl', function ($scope, TodoSvc) {
$scope.todos = [{title: 'Get paper'}, {title:'Mail rent check'}];
$scope.refresh = function () {
TodoSvc.fetch()
.then(function (todos) {
$scope.todos = todos.data;
});
}
$scope.addTodo = function () {
TodoSvc.add($scope.newTodo)
.then(function () {
$scope.newTodo = {};
$scope.refresh();
});
}
$scope.refresh();
});
angular.module('app')
.service('TodoSvc', function ($http) {
this.fetch = function () {
return $http.get('/api/todos');
};
this.add = function (todo) {
return $http.post('/api/todos', todo);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment