![](/img/trans.png)
[英]Passing value from Parent component to child component for ngForm in angular2?
[英]Passing value from parent component to child component by reference
我有2個組件: parentComponent
和childComponent
。 在parentComponent
我有一個FormGroup
類型值作為parentForm
,它通過@input
傳遞給childComponent
:
export class parentComponent {
...
parentForm: FormGroup;
....
}
export class childComponent {
...
@Input()
childForm :FormGroup; //The parentForm
....
}
當我運行這些代碼時,一切正常,我的childComponent
識別出childForm
,這是parentComponent
的輸入值,但是每當我更改parentComponent
中parentForm
中的某些屬性時, childComponent
都無法意識到這些變化,並且在調試代碼時,我看到了該childComponent
持有舊的輸入值,沒有更新的變化childForm
在childComponent
。 現在,我試圖找到一種方法來傳遞parentForm
的引用以解決我的問題。 因為我認為通過這種方式, parentForm
任何更改都會立即通知childForm
。 我不知道怎么可能。 (Angular的版本是5.0.1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.