This thing is the source of a truly nasty bug I found in my code.
So I have a child-component:
chilidComponent {
@Input("current-value") currentValue: Array<{id: string, name: string}>
}
and the parent component uses child component like this
<child-component [current-value]="parentList"></child-component>
now if child component does something like
this.currentValue.push({id: "someId", name: "someName"})
the parent component have its "parentsList" modified even if there isn't an explicit two-way binding.
I know that objects (like an Array) are passed by reference, BUT is this a legit/wanted way for Angular to handle the component input?
What is the best practice for passing objects as inputs? How can I pass and object to a component that I don't want it to get modified even if it does inside the component?
Working with clones (inside or outside the child-component) sounds to me like a workaround you have to be aware of everytime component inputs are objects.
Should I start looking into Facebook's Immutable.js ?