2017-07-30 64 views
0

我有例如這可能會返回與新數據相同的組件?

export class DataTableComponent implements OnInit { 
Input() bar : string; 
... 
template: '<div> {{bar}}' 
} 

組件是否有可能這個組件從那裏用新的數據充值?

像這樣的事情

recallComponents(DataTableComponent, "foo_1"); 
recallComponents(DataTableComponent, "foo_2"); 

回答

1

你應該看看爲實現其將改變數據的observable

可觀察對象打開了一個連續的通信通道,其中可以隨時間發射多個數據值。由此我們可以通過使用類似數組的操作來解析,修改和維護數據,從而獲得處理數據的模式。 https://angular-2-training-book.rangle.io/handout/observables/

例如:

let subscription = this.data.subscribe(
    value => this.values.push(value), // on change 
    error => this.anyErrors = true, // on error 
    () => this.finished = true // on complete 
); 

這裏是一個工作plunkr,展示瞭如何可以在項目中使用它們的例子..


另請注意:

[a] Rou在導航到相同組件時,ter可能不會重新創建組件。在這種情況下,參數可能會更改,而不重新創建組件。 https://angular-2-training-book.rangle.io/handout/routing/routeparams.html

相關問題