Permalink
Browse files

DELETE: clicking X

  • Loading branch information...
1 parent 2664150 commit 161be3b1a0e59ea41442d7be99d61fb9bb81b8b5 @amejiarosario committed Oct 17, 2016
Showing with 15 additions and 2 deletions.
  1. +1 −1 src/app/todo/todo.component.html
  2. +6 −0 src/app/todo/todo.component.ts
  3. +8 −1 src/app/todo/todo.service.ts
@@ -22,7 +22,7 @@
<div class="view">
<input class="toggle" type="checkbox" [checked]="todo.isDone">
<label (dblclick)="todo.editing = true">{{todo.title}}</label>
- <button class="destroy"></button>
+ <button class="destroy" (click)="destroyTodo(todo)"></button>
</div>
<input class="edit"
#updatedTodo
@@ -41,4 +41,10 @@ export class TodoComponent implements OnInit {
return this.getTodos();
});
}
+
+ destroyTodo(todo){
+ this.todoService.delete(todo._id).then(() => {
+ return this.getTodos();
+ });
+ }
}
@@ -29,6 +29,13 @@ export class TodoService {
todos[index].title = data.title;
resolve(data);
});
- }
+ }
+ delete(id) {
+ return new Promise(resolve => {
+ let index = todos.findIndex(todo => todo._id === id);
+ todos.splice(index, 1);
+ resolve(true);
+ });
+ }
}

0 comments on commit 161be3b

Please sign in to comment.