I am trying to get routerLink Parameter using ActivatedRoute.
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.pageTitle = this.route.snapshot.params['title'];
}
It shows the parameter first time only. But not again when the parameter is changed.
Link to StackBlitz example.
When I click Search Page a it shows title is test. But when I click on Search Page b it still keeps on showing title is test even though the title is testing. However when I click Home and then Search Page b it shows the updated parameter as testing.
How do I fix the issue so that when click Search Page b after Search Page a it shows me the updated parameter.
The way you have it, it works one time and one time only. It won't work for your criteria. If you would like to react, you have to do it in an observable way.
Try:
this.route.params.subscribe(params => {
this.pageTitle = params['title'];
});
Everytime the params changes, you will get a notification and the subscription will kick in and change the pageTitle
.