且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过 Angular 应用程序中的路由更改页面标题?

更新时间:2023-11-24 19:38:10

您在 Angular 5 中有一个 TitleService.将它注入到您组件的构造函数中,并使用 setTitle() 方法.

You have a TitleService in Angular 5. Inject it in your component's constructor, and use the setTitle() method.

import {Title} from "@angular/platform-browser";

....

constructor(private titleService:Title) {
  this.titleService.setTitle("Some title");
}

这里是来自 Angular 的文档:https://angular.io/guide/set-document-标题

Here are the docs from Angular: https://angular.io/guide/set-document-title