import { Component , OnInit } from '@angular/core' ; import { Router , ActivatedRoute , NavigationEnd , Route } from '@angular/router' ; import { Title } from '@angular/platform-browser' ; import { app_title } from 'config/global-config' ; import 'rxjs/add/operator/filter' ; import 'rxjs/add/operator/map' ; import 'rxjs/add/operator/mergeMap' ; @ Component ( { selector : 'app-root' , template : '<router-outlet></router-outlet>' } ) export class AppComponent implements OnInit { constructor ( private router , private activatedRoute , private titleService ) { } ngOnInit ( ) { this . addTitle ( ) ; } private addTitle ( ) { this . router . events . filter ( event => event instanceof NavigationEnd ) . map ( ( ) => this . activatedRoute ) . map ( route => { while ( route . firstChild ) { route = route . firstChild ; } return route ; } ) . filter ( route => route . outlet === 'primary' ) . mergeMap ( route => route . data ) . subscribe ( ( event ) => { if ( event && event [ 'title' ] ) { return this . titleService . setTitle ( app_title + '-' + event [ 'title' ] ) ; } else { return this . titleService . setTitle ( app_title ) ; } } ) ; } }