I have an angular component with in which i am trying to bind a public variable based on the router URL. The public variable is assigned a value inside subscribe method, so because of this the template is not updated on initial load.
pageTitle: string;
constructor(private router: Router) {}
ngOnInit() {
this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
if(event.url ==="something" {
this.pageTitle ="About US"
}
}
})
}
I am binding the pageTitle variable in the HTML file
<div class="title">{{pageTitle}}</div>
On refreshing the page, i am able to see the pageTitle, but on initial load the value is not shown.