I have a use case where a parent component has two child components. When a child component is selected, the parents FormControl should be reset.
In order to do this, I need to send a boolean value from the children to the parent, but this is not functioning as expected.
Here is my current implementation - which is not working! Could someone explain what I am overlooking? Many thanks
Child component
Register the event emitter in the child
@Output() formControlReset: EventEmitter<boolean> = new EventEmitter();
emit the event
this.formControlReset.emit(true);
Parent Component
<div>
<input (formControlReset)="formControlReset($event)" [(ngModel)]="userInput" [formControl]="inputFormControl" *ngIf="showSearchInput" placeholder="Search here" #searchInput></input>
</div>
call a reset on the formControl
formControlReset(value: boolean): void {
console.log('doing something');
this.inputFormControl.reset();
}
<button (click)="onClick()">Click </button>
. Then call itonClick(){this.formControlReset.emit(true);}
– Iancovici