Skip to content

Commit

Permalink
DELETE: clicking X
Browse files Browse the repository at this point in the history
  • Loading branch information
amejiarosario committed Oct 17, 2016
1 parent 2664150 commit 161be3b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/app/todo/todo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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
Expand Down
6 changes: 6 additions & 0 deletions src/app/todo/todo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ export class TodoComponent implements OnInit {
return this.getTodos();
});
}

destroyTodo(todo){
this.todoService.delete(todo._id).then(() => {
return this.getTodos();
});
}
}
9 changes: 8 additions & 1 deletion src/app/todo/todo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.