Skip to content
Permalink
Browse files

Filtering data based on the route

  • Loading branch information
amejiarosario committed Aug 7, 2018
1 parent 1c12161 commit 653e5434fff403f6d5aabc27208143170758d13d
Showing with 16 additions and 5 deletions.
  1. +3 −3 src/app/todo/todo.component.ts
  2. +13 −2 src/app/todo/todo.service.ts
@@ -17,8 +17,8 @@ export class TodoComponent implements OnInit {

constructor(private todoService: TodoService, private route: ActivatedRoute) { }

getTodos() {
return this.todoService.get().then(todos => {
getTodos(query = ''){
return this.todoService.get(query).then(todos => {
this.todos = todos;
this.activeTasks = this.todos.filter(todo => todo.isDone).length;
});
@@ -49,7 +49,7 @@ export class TodoComponent implements OnInit {
ngOnInit() {
this.route.params.subscribe(params => {
this.path = params['status'];
this.getTodos();
this.getTodos(this.path);
});
}
}
@@ -14,8 +14,19 @@ export class TodoService {

constructor() { }

get() {
return new Promise(resolve => resolve(TODOS));
get(query = '') {
return new Promise(resolve => {
let data;

if (query === 'completed' || query === 'active'){
const isCompleted = query === 'completed';
data = TODOS.filter(todo => todo.isDone === isCompleted);
} else {
data = TODOS;
}

resolve(data);
});
}

add(data) {

0 comments on commit 653e543

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