1constructor(private activatedRoute: ActivatedRoute) {
2 this.activatedRoute.queryParams.subscribe(params => {
3 let date = params['startdate'];
4 console.log(date); // Print the parameter to the console.
5 });
6}
7
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 { ActivatedRoute } from "@angular/router";
2
3//import ActivatedRoute in constructor()
4private $route: ActivatedRoute
5
6// in ngOnInit() call
7//myvar is the variable where you want to store your param
8this.$route.params.forEach(param =>
9 this.myvar = param['whatever your param name is']
10);
1// example url: details?id=2
2
3constructor(private activatedRoute: ActivatedRoute) {
4 this.activatedRoute.queryParams.subscribe(params => {
5 console.log(params); // Prints {id: "2"}
6 });
7}
8