如何使用有角度的'标题'API?

时间:2017-11-14 15:47:20

标签: angular

我想动态获取或设置页面的标题。我发现this但我不知道如何使用它。

2 个答案:

答案 0 :(得分:1)

你可以这样做:

export class AppComponent {
  public constructor(private titleService: Title ) { }

  public setTitle( newTitle: string) {
    this.titleService.setTitle( newTitle );
  }
}

来源:https://angular.io/guide/set-document-title

答案 1 :(得分:1)

这很简单。在要操作标题的组件中,添加以下内容:

<强> component.ts

constructor(private documentTitle: Title) {
    documentTitle.setTitle('Whatever title you want');
}