你好,我想分享組件之間的標題。我有組件app.component聲明標題屬性和所有其他組件是兒童。我有page-header.component寫標題的HTML和dashboard.component設置標題屬性和標題不顯示。這裏是我的代碼:Angular2在組件之間共享數據
app.component
export class AppComponent implements OnInit {
title: string;
ngOnInit(): void {
}
}
頁面header.component
export class PageHeaderComponent extends AppComponent implements OnInit {
constructor() {
super();
}
ngOnInit() {
super.ngOnInit();
}
}
頁面header.component.html
<h1>{{title}}</h1>
dashboard.component
export class DashboardComponent extends AppComponent {
constructor() {
super();
}
ngOnInit() {
super.ngOnInit();
this.title = "Dashboard";
}
}
我想容易集標題中的任何組件(AppComponent的孩子)和標題將被寫入到頁頭標組件
你可以創建一個'共component'和使用它通過讓其他組件作爲子頁面穿過頁面 – Aravind