2017-10-09 23 views
0

最好是它爲一個子組件有一個對象的屬性的輸入和改變發射器,或雙向綁定到對象像這樣:角2最佳實踐:綁定的對象VS結合其屬性

實施例1

<parent-component> 
    <child-component [exampleInput]="object.val" 
        (valueChanged)="updateObjectValue($event)"> 
    </child-component> 
</parent-component> 

VS實施例2

<parent-component> 
    <child-component [(obj)]="object"></child-component> 
</parent-component> 

其中實施例2的子組件將處理updateObjectValue邏輯。

在我們的代碼,現在,這樣的組件目前有4個輸入和2個輸出,而如果減少1個屬性通過直接結合它的對象是罰款會是真棒

回答