Permalink
Browse files

CREATE: new todo elements

  • Loading branch information...
1 parent 2712e68 commit 049b52b4d823c62f922e5d6e5f386fa96cc6b0fe @amejiarosario committed Oct 17, 2016
Showing with 21 additions and 2 deletions.
  1. +5 −1 src/app/todo/todo.component.html
  2. +9 −1 src/app/todo/todo.component.ts
  3. +7 −0 src/app/todo/todo.service.ts
@@ -2,7 +2,11 @@
<header class="header">
<h1>Todo</h1>
- <input class="new-todo" placeholder="What needs to be done?" autofocus>
+ <input class="new-todo"
+ placeholder="What needs to be done?"
+ [(ngModel)]="newTodo"
+ (keyup.enter)="addTodo()"
+ autofocus>
</header>
<!-- This section should be hidden by default and shown when there are todos -->
@@ -24,5 +24,13 @@ export class TodoComponent implements OnInit {
this.todos = todos;
this.activeTasks = this.todos.filter(todo => todo.isDone).length;
});
- }
+ }
+
+ addTodo(){
+ this.todoService.add({ title: this.newTodo, isDone: false }).then(() => {
+ return this.getTodos();
+ }).then(() => {
+ this.newTodo = ''; // clear input form value
+ });
+ }
}
@@ -16,4 +16,11 @@ export class TodoService {
return new Promise(resolve => resolve(todos));
}
+ add(data) {
+ return new Promise(resolve => {
+ todos.push(data);
+ resolve(data);
+ });
+ }
+
}

0 comments on commit 049b52b

Please sign in to comment.