Imagine having a scenario where I create a component that takes a Foo
instance and generates a form for editing.
export class ChildComponent implements OnInit {
@Input() foo : Foo;
@Output() onChange : EventEmitter<Foo> = new EvenEmitter<Foo>();
constructor() {
}
ngOnInit() {
}
}
I then include this ChildComponent
within a ParentComponent
.
<div id="parent">
<app-child-component [foo]="parentFoo"></app-child-component>
</div>
Although I used one-way binding, the fact that foo
is an object passed by reference means any changes made to it in ChildComponent
will also affect ParentComponent
.
Is there a way to avoid this or pass by value instead? Are there any recommended practices?