I'm fairly new to Angular, hoping someone can shed some light on this.
Method 1: Say I'm passing a parent object 'x' to a child component using 1 way data binding:
<app-child [x]="x"></app-child>
and my child component modifies it like so in ts:
Input() x;
then later:
this.x.someProperty = 'some new value';
This seems to work fine, my 'x' object in the parent is updated.
However in Angular tutorials & other examples (eg https://stackoverflow.com/a/41465022) it seems the 'proper' way to do this would be Method 2: to use 2 way binding eg:
<app-child [(x)]="x"></app-child>
and in the ts
@Input() x: any;
@Output() xChange = new EventEmitter<any>();
then later:
this.x.someProperty = 'some new value';
this.xChange.emit(x);
I'm currently very happily using Method 1 in Angular 7 without any problems - can anyone explain why (if at all) I should use method 2 instead? It seems more complicated & unnecessary since Method 1 works.