Permalink
Browse files

Step 8: add basic frontend for POST /todo.json

  • Loading branch information...
vkarpov15 committed Jul 25, 2013
1 parent 67859d3 commit 5f108282aa99d750322cf4a2929de3b83454a4d8
Showing with 19 additions and 1 deletion.
  1. +13 −1 public/javascripts/controllers/TodoListController.js
  2. +6 −0 views/index.jade
@@ -1,10 +1,22 @@
function TodoListController($scope) {
function TodoListController($scope, $http) {
$scope.todos = [];
$scope.newTodo = {
done : false,
due : new Date(new Date().getTime() + 24 * 60 * 60 * 1000),
description : ''
};
$scope.doneFilter = { done : true };
$scope.notDoneFilter = { done : false };
$scope.setTodos = function(todos) {
$scope.todos = todos;
};
$scope.addNewTodo = function() {
$http.post('/todo.json', $scope.newTodo).success(function(data) {
$scope.todos = data.todos;
$scope.newTodo.description = '';
});
};
}
View
@@ -8,6 +8,12 @@ block head
block content
div.container(ng-controller="TodoListController", ng-init="setTodos( #{JSON.stringify(todos)} )")
h1 My Todo List
h2 Add New
form(novalidate, ng-submit="addNewTodo()")
textarea( ng-model="newTodo.description",
placeholder="Description")
br
button.btn.btn-primary(type="submit") Add Todo
h2 Upcoming
div
div.row.todo.not-done(ng-repeat="todo in todos | filter:notDoneFilter")

0 comments on commit 5f10828

Please sign in to comment.