I am trying to get url parameter value but it is undefined and I don't find why...
Code
export class HeaderComponent implements OnInit {
constructor(private route: ActivatedRoute) { }
ngOnInit(): void {
console.log(this.route.snapshot.params['lang']);
}
}
URL
localhost:4200/home?lang=EN
CodePudding user response:
What you are looking for is queryParams
not params
.
params
is for myRoute/mySubRoute/:myParam:/
queryParams
is for myRoute/mySubRoute?param=value
where ?param=value
is the queryString
.
CodePudding user response:
export class HeaderComponent implements OnInit {
constructor(private route: ActivatedRoute) { }
ngOnInit(): void {
console.log(this.route.snapshot.queryParams['lang']);
}
}