I have two components:
Parent component HTML:
<parent-component>
<child-component [input]="inputValue"> </child-component>
<child-component [input]="inputValue"> </child-component>
<button mat-stroked-button> Submit </button>
</parent-component>
Parent component TS: here I was trying to test if ViewChild wokrs correctly and it is. I get a property value from child in my parent component.
export class ParentComponent implements OnInit {
@ViewChild(ChildComponent) childReference;
parentString: string;
constructor(
private cdRef: ChangeDetectorRef,
) { }
ngOnInit() {
}
ngAfterViewInit() {
this.parentString = this.childReference.exampleChild;
this.cdRef.detectChanges();
}
In my child component html I have a couple of <mat-form-field>
inputs:
<form [formGroup]="myForm">
<mat-form-field>
<input matInput formControlName="myInput">
</mat-form-field>
<mat-form-field>
<input matInput formControlName="myInput2">
</mat-form-field>
</form>
But how to properly get an matInput values from child component in the parent component when the actual submit button is in the parent?