Skip to content

Commit

Permalink
Using routerLink and ActivatedRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
amejiarosario committed Nov 7, 2019
1 parent 2e2bae9 commit b3487a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/app/todo/todo.component.html
Expand Up @@ -38,13 +38,13 @@ <h1>Todo</h1>
<!-- Remove this if you don't implement routing -->
<ul class="filters">
<li>
<a class="selected" href="#/">All</a>
<a [routerLink]="['/all']" [class.selected]="path === 'all'">All</a>
</li>
<li>
<a href="#/active">Active</a>
<a [routerLink]="['/active']" [class.selected]="path === 'active'">Active</a>
</li>
<li>
<a href="#/completed">Completed</a>
<a [routerLink]="['/completed']" [class.selected]="path === 'completed'">Completed</a>
</li>
</ul>
<!-- Hidden if no completed items are left ↓ -->
Expand Down
16 changes: 11 additions & 5 deletions src/app/todo/todo.component.ts
@@ -1,4 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { TodoService } from './todo.service';

@Component({
Expand All @@ -11,8 +13,16 @@ export class TodoComponent implements OnInit {
private todos;
private activeTasks;
private newTodo;
private path;

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

constructor(private todoService: TodoService) { }
ngOnInit() {
this.route.params.subscribe(params => {
this.path = params['status'];
this.getTodos();
});
}

addTodo(){
this.todoService.add({ title: this.newTodo, isDone: false }).then(() => {
Expand All @@ -37,10 +47,6 @@ export class TodoComponent implements OnInit {
});
}

ngOnInit() {
this.getTodos();
}

destroyTodo(todo) {
this.todoService.delete(todo).then(() => {
return this.getTodos();
Expand Down

0 comments on commit b3487a2

Please sign in to comment.