Permalink
Browse files

Clearing out completed tasks

1 parent fd0a228 commit 333c0127f1fcc7949e0b0138933dc6aaf7044fe3 @amejiarosario committed Oct 19, 2016
Showing with 14 additions and 1 deletion.
  1. +1 −1 src/app/todo/todo.component.html
  2. +6 −0 src/app/todo/todo.component.ts
  3. +7 −0 src/app/todo/todo.service.ts
@@ -51,6 +51,6 @@
</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,10 @@ export class TodoComponent implements OnInit {
return this.getTodos();
});
}
+
+ clearCompleted() {
+ this.todoService.deleteCompleted().then(() => {
+ return this.getTodos();
+ });
+ }
}
@@ -49,4 +49,11 @@ export class TodoService {
resolve(true);
});
}
+
+ deleteCompleted() {
+ return new Promise(resolve => {
+ todos = todos.filter(todo => !todo.isDone);
+ resolve(todos);
+ });
+ }
}

0 comments on commit 333c012

Please sign in to comment.