Skip to content
Permalink
Browse files

DELETE: clicking X

  • Loading branch information
amejiarosario committed Nov 7, 2019
1 parent f1270ef commit a4aeaa45bb250c3a6d2447cb25306ea1a28675fe
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
@@ -17,7 +17,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
@@ -40,4 +40,10 @@ export class TodoComponent implements OnInit {
ngOnInit() {
this.getTodos();
}

destroyTodo(todo) {
this.todoService.delete(todo).then(() => {
return this.getTodos();
});
}
}
@@ -33,4 +33,12 @@ export class TodoService {
});
}

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

}

0 comments on commit a4aeaa4

Please sign in to comment.
You can’t perform that action at this time.