【问题标题】:Angular 2 router title with parameter带参数的 Angular 2 路由器标题
【发布时间】:2017-02-01 03:21:09
【问题描述】:

假设我使用以下表达式在路由器中为 angular 组件设置页面标题:

{ 路径:'view-move/:moveName',组件:ViewMoveComponent,数据:{title:'View Move'} }

假设我使用路由器参数来获取 Move 详细信息,包括他的名字,我如何将 move 名称放在我的标题中,所以它会像:

查看移动:移动名称

更新:我试过了:

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

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

现在没有标题

【问题讨论】:

    标签: angular


    【解决方案1】:

    您需要将TitleService 注入组件并使用其setTitle 方法。

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

    【讨论】:

    • import { BrowserModule, Title } from '@angular/platform-browser'; constructor(public http: Http,private route: ActivatedRoute,private titleService: Title) { this.titleService.setTitle("My Title"); } 不要设置任何标题
    • 您必须将服务添加到应用模块中的 providers 数组中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 2020-08-30
    • 2017-03-22
    • 2017-03-04
    相关资源
    最近更新 更多