Last active
October 16, 2015 21:11
-
-
Save jdx/f69225637e7c8f9eca65 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
'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