Permalink
Browse files

Using routerLink and ActivatedRoute

  • Loading branch information...
1 parent 4a7f715 commit bd3cc91ae8aed975c7d6e64ad76c53e985726364 @amejiarosario committed Oct 18, 2016
Showing with 10 additions and 5 deletions.
  1. +3 −3 src/app/todo/todo.component.html
  2. +7 −2 src/app/todo/todo.component.ts
@@ -41,13 +41,13 @@
<!-- 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 ↓ -->
@@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core';
+import { ActivatedRoute } from '@angular/router';
import { TodoService } from './todo.service';
@@ -12,11 +13,15 @@ export class TodoComponent implements OnInit {
private todos;
private activeTasks;
private newTodo;
+ private path;
- constructor(private todoService: TodoService) { }
+ constructor(private todoService: TodoService, private route: ActivatedRoute) { }
ngOnInit() {
- this.getTodos();
+ this.route.params.subscribe(params => {
+ this.path = params['status'];
+ this.getTodos();
+ });
}
getTodos(){

0 comments on commit bd3cc91

Please sign in to comment.