I'm using a child component to build a complex object consisting of recursive child arrays and objects. I'd like a way to get access to this object in the parent component using live binding.
Values within the object change based on user input (select boxes, inputs etc.), so I need a way to emit the @Output() EventEmitter and pass the entire object whenever one if it's properties change.
Any ideas on how to accomplish this or is there another route I can take?
See some concept code below, in which the input has two-way data binding to a deep value in the complex object, and I need to emit this change to a parent by detecting the change somehow.
The actual form is more complex, so I'd like to avoid using specific events like watching for a change in each of the inputs to manually trigger the event emitter if possible.
Parent template:
<child-component (emitter)="emitterHandler($event)"></child-component>
Parent component:
emitterHandler(obj){ console.log(obj); }
Child component:
@Output() emitter: EventEmitter<any> = new EventEmitter();
complexObj = {data: 'test', lines: [{data: 'asd', time: 123},{data: 'xcv', time: 233}]};
Child template:
<input [(ngModel)]="complexObj.lines[0].data"></input>
<input [(ngModel)]="complexObj.lines[0].data" (change)="emitEmitter()"></input>
– JayDeeEss