1
2// ...
3import { ActivatedRoute } from '@angular/router';
4import 'rxjs/add/operator/filter';
5
6@Component({ ... })
7export class BookComponent implements OnInit {
8
9 category: string;
10
11 constructor(private route: ActivatedRoute) { }
12
13 ngOnInit() {
14 this.route.queryParams
15 .filter(params => params.category)
16 .subscribe(params => {
17 console.log(params); // { category: "fiction" }
18 this.category = params.category;
19 console.log(this.category); // fiction
20 }
21 );
22 }
23}
24
25