0
我希望我的頁面顯示2個選項卡,每個選項卡都將包含一個表。 由於表的結構相同,我爲表創建了一個自定義組件,並將其用作子組件。 父頁面:Angular2:在父級中使用兩個相同的子組件
<p-tabPanel>
<cutomComp #table1 [items]=>"variable1"</customComp>
</<p-tabPanel>
<p-tabPanel>
<cutomComp #table2 [items]="variable2"></customComp>
</<p-tabPanel>
我的自定義組件:
<p-dataTable [value]="itemsForTable">
</p-dataTable>
ngOnChanges(changes: SimpleChanges){
//init itemsForTable from items
}
的問題是,該表被更新(ngOnChanges叫法),只有當變量1被改變,而不是當變量2被改變。爲什麼? 另外,當變量1的ngOnChanges被執行時,表2也被更新了。 那麼問題是什麼?我希望每張桌子都是獨立的,我怎麼能做到這一點?
在此先感謝。
'[items] =>「variable1」'是一個可能的罪魁禍首,如果它在你的實際代碼中 –