I have set up routes is like below
const appRoutes: Routes = [
{
path: \'login\',
component: LoginComponent,
data: {
title: \'Login TTX\
its work for component that not navigate (like header) :
this.route.root.firstChild.snapshot.data['title']
and complete example:
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router, NavigationEnd } from '@angular/router';
export class HeaderComponent implements OnInit {
title: string;
constructor(private route: ActivatedRoute, private router: Router ) { }
ngOnInit() {
this.router.events.subscribe(event => {
if(event instanceof NavigationEnd) {
this.title = this.route.root.firstChild.snapshot.data['title']
}
});
}
}
cerdit to this answare