雙向繫結

通過引用傳遞值,你希望在兩個範圍之間共享值並從兩個範圍操作它們。你不應該使用{{…}}進行插值。

<two-way text="'Simple text.'" <!-- 'Simple text.' -->
         simple-value="123" <!-- 123 Note, is actually a number now. -->
         interpolated-value="parentScopeValue" <!-- Some value from parent scope. You may change it in one scope and have updated value in another. -->
         object-item="objectItem" <!-- Some object from parent scope. You may change object properties in one scope and have updated properties in another. -->
         
         <!-- Unexpected usage. -->
         interpolated-function-value="parentScopeFunction()" <!-- Will raise an error. -->
         function-item="incrementInterpolated"> <!-- Pass the function by reference and you may use it in child scope. -->
</two-way>

通過引用傳遞函式是一個壞主意:允許範圍更改函式的定義,並且將建立兩個不必要的觀察者,你需要最小化觀察者計數。