1import { ActivatedRoute, Params } from '@angular/router';
2
3@Component(...)
4export class MyComponent implements OnInit {
5 constructor (private activatedRoute: ActivatedRoute){}
6
7 ngOnInit() {
8 this.activatedRoute.params.subscribe((params: Params) => {
9 if (params.myParam){
10 // Do something
11 }
12 });
13 }
14}
15
1import { Component } from '@angular/core';
2import { Router } from '@angular/router';
3
4@Component({
5 template: 'The href is: {{href}}'
6 /*
7 Other component settings
8 */
9})
10export class Component {
11 public href: string = "";
12
13 constructor(private router: Router) {}
14
15 ngOnInit() {
16 this.href = this.router.url;
17 console.log(this.router.url);
18 }
19}