在Angular中,可以使用Title
服务来动态修改页面的标题。
import { Title } from '@angular/platform-browser';
constructor(private titleService: Title) {}
然后,你可以使用Title
服务的setTitle
方法来动态设置页面标题
this.titleService.setTitle('新标题');
完整示例:
import { Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
@Component({
selector: 'app-example',
templateUrl: './example.component.html',
styleUrls: ['./example.component.css']
})
export class ExampleComponent implements OnInit {
constructor(private titleService: Title) {}
ngOnInit() {
this.titleService.setTitle('动态标题');
}
}