Permalink
Browse files

Filtering data based on route

  • Loading branch information...
amejiarosario committed Oct 19, 2016
1 parent bd3cc91 commit fd0a228c4768050b4dcae174f034ffa09931324d
Showing with 19 additions and 8 deletions.
  1. +6 −6 src/app/todo/todo.component.ts
  2. +13 −2 src/app/todo/todo.service.ts
@@ -20,12 +20,12 @@ export class TodoComponent implements OnInit {
ngOnInit() {
this.route.params.subscribe(params => {
this.path = params['status'];
this.getTodos();
});
this.getTodos(this.path);
});
}
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;
});
@@ -44,12 +44,12 @@ export class TodoComponent implements OnInit {
return this.todoService.put(todo).then(() => {
todo.editing = false;
return this.getTodos();
});
});
}
destroyTodo(todo){
this.todoService.delete(todo._id).then(() => {
return this.getTodos();
});
}
}
}
@@ -12,8 +12,19 @@ export class TodoService {
constructor() { }
get(){
return new Promise(resolve => resolve(todos));
get(query = ''){
return new Promise(resolve => {
var data;
if(query === 'completed' || query === 'active'){
var isCompleted = query === 'completed';
data = todos.filter(todo => todo.isDone === isCompleted);
} else {
data = todos;
}
resolve(data);
});
}
add(data) {

0 comments on commit fd0a228

Please sign in to comment.