我在我的 app.component.html
文件中有一个出现在每个页面上的元素:
<h1 i18n="@@titleH1">{{title}}</h1>
我有一个共享服务,它拥有设置器(setters)和获取器(getters):
...
title = new BehaviorSubject('Initial Title');
setTitle(title: string) {
this.title.next(title);
}
...
app.component.ts: ngOnInit
...
this.sharedService.title.subscribe(updateTitle => this.title = updateTitle);
this.sharedService.setTitle('Dashboard');
...`
product.component.ts: ngOnInit
...
this.sharedService.title.subscribe(updateTitle => this.title = updateTitle);
this.sharedService.setTitle('Product');
...
当我导航到 /dashboard 时,