Skip to content
Permalink
Browse files

Clearing out completed tasks

  • Loading branch information
amejiarosario committed Nov 7, 2019
1 parent b87857d commit 30c699b24c9d4916bb7b1fa12c117bb7bae456bd
Showing with 16 additions and 2 deletions.
  1. +1 −1 src/app/todo/todo.component.html
  2. +7 −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>
@@ -52,4 +52,11 @@ export class TodoComponent implements OnInit {
return this.getTodos();
});
}

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

}
@@ -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 },
@@ -52,4 +52,11 @@ export class TodoService {
});
}

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

}

0 comments on commit 30c699b

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