I have a simple route with 1 parameter:
{
path: 'item/:id',
component: ItemComponent,
data: {title: 'Item detail'}
}
I'm setting page title using data title property in main AppComponent:
export class AppComponent implements OnInit {
title: string;
ngOnInit() {
this.router.events
.. parse it
.subscribe((event) => {
this.title = event['title'];
});
}
}
Then I'm just displaying it in AppComponent template:
<h1>{{ title }}</h1>
The problem is if I want to have dynamic title like "Item detail #name(:id)". Is there any way how can I add e.g. route param (:id) or variable into data title property? Something like
{
path: 'item/:id',
component: ItemComponent,
data: {title: 'Item detail #' + :id }
}
data.titleparam as a "blueprint" and do a search/replace from within the component.router.eventsto extract the route data/params? (instead of justroute.dataandroute.params)ActivatedRoute(.snapshot).