正如我从 Angular2 论坛上读到的,我们可以通过在 app.component.ts 和 app.module.ts 上进行更改来更改 html 页面的标题。有没有办法在单个页面上进行此更改而无需在 app.component.ts 上进行任何更改?因为我有太多组件,我不想在所有页面或组件上显示标题名称更改?我可以对单个组件的 ts 进行更改吗?你能给我提供样品吗?
问候阿尔珀
AppModule
import { NgModule } from '@angular/core';
import { BrowserModule, Title } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule
],
declarations: [
AppComponent
],
providers: [
Title
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
应用组件
export class AppComponent {
public constructor(private titleService: Title ) { }
public setTitle( newTitle: string) {
this.titleService.setTitle( newTitle );
}
}