how to change page title in angular2 router

后端 未结 14 1267
深忆病人
深忆病人 2020-12-04 16:17

I am trying to change the page title from the router, can this be done?

import {RouteConfig} from \'angular2/router\';
@RouteConfig([
  {path: \'/home\', com         


        
14条回答
  •  再見小時候
    2020-12-04 16:57

    Angular 6+

    if route configured as follow :-

    Routes = [
         {  path: 'dashboard',
           component: DashboardComponent,
           data: {title: 'Dashboard'}
       }]
    

    **Then in component constructor title can be set as follow :- **

     constructor( private _titleService: Title, public activatedRoute: ActivatedRoute) {
        activatedRoute.data.pipe(map(data => data.title)).subscribe(x => this._titleService.setTitle(x));
       }
    

提交回复
热议问题