2016-09-23 104 views
4

假设我使用以下表达式来设置角度成分页面标题在我的路由器:角2路由器标题与参数

{路径:“视图-移动/:moveName”,组分:ViewMoveComponent,数据:{标题:“查看移动”}}

假设我用的路由器PARAMS获得移动细节,包括他的名字,我怎么可以把移动名字我的标题里面,所以它会像:

查看移动:移动名称

更新:我想:

import { BrowserModule, Title } from '@angular/platform-browser'; 

constructor(public http: Http,private route: ActivatedRoute,private titleService: Title) { 
this.titleService.setTitle("My Title"); 
    } 

没有标题现在

回答

0

您需要的TitleService注入到你的组件,并使用其setTitle方法。

https://angular.io/docs/ts/latest/cookbook/set-document-title.html

+0

'进口{BrowserModule,标题}从 '@角/平台的浏览器'; 构造函数(公共http:Http,私人路由:ActivatedRoute,私人titleService:标题){ this.titleService.setTitle(“My Title”); }'不设置任何标题 – TheUnreal

+0

您必须将服务添加到应用程序模块中的providers数组中 –