Permalink
Browse files

DELETE: clicking X

  • Loading branch information...
amejiarosario committed Aug 7, 2018
1 parent 7f7700b commit 4703dd01d19ed3d84501e67f7fef5b51dee7585e
Showing with 15 additions and 1 deletion.
  1. +1 −1 src/app/todo/todo.component.html
  2. +6 −0 src/app/todo/todo.component.ts
  3. +8 −0 src/app/todo/todo.service.ts
@@ -20,7 +20,7 @@ <h1>Todo</h1>
<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
@@ -37,6 +37,12 @@ export class TodoComponent implements OnInit {
});
}

destroyTodo(todo) {
this.todoService.delete(todo).then(() => {
return this.getTodos();
});
}

ngOnInit() {
this.getTodos();
}
@@ -32,4 +32,12 @@ export class TodoService {
resolve(changed);
});
}

delete(selected) {
return new Promise(resolve => {
const index = TODOS.findIndex(todo => todo === selected);
TODOS.splice(index, 1);
resolve(true);
});
}
}

0 comments on commit 4703dd0

Please sign in to comment.