Skip to content
Permalink
Browse files

clear completed tasks

  • Loading branch information
amejiarosario committed Aug 7, 2018
1 parent 653e543 commit 4ef542fdfe2cd6b78835cb966ac45e838fbee1c6
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
@@ -48,6 +48,6 @@ <h1>Todo</h1>
</li>
</ul>
<!-- Hidden if no completed items are left ↓ -->
<button class="clear-completed">Clear completed</button>
<button class="clear-completed" (click)="clearCompleted()">Clear completed</button>
</footer>
</section>
@@ -46,6 +46,12 @@ export class TodoComponent implements OnInit {
});
}

clearCompleted() {
this.todoService.deleteCompleted().then(() => {
return this.getTodos();
});
}

ngOnInit() {
this.route.params.subscribe(params => {
this.path = params['status'];
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';

const TODOS = [
let TODOS = [
{ title: 'Install Angular CLI', isDone: true },
{ title: 'Style app', isDone: true },
{ title: 'Finish service functionality', isDone: false },
@@ -51,4 +51,11 @@ export class TodoService {
resolve(true);
});
}

deleteCompleted() {
return new Promise(resolve => {
TODOS = TODOS.filter(todo => !todo.isDone);
resolve(TODOS);
});
}
}

0 comments on commit 4ef542f

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