У меня есть два компонента:
Родительский компонент HTML:
<parent-component>
<child-component [input]="inputValue"> </child-component>
<child-component [input]="inputValue"> </child-component>
<button mat-stroked-button> Submit </button>
</parent-component>
Родительский компонент TS: здесь я пытался проверить, правильно ли работает ViewChild wokrs.Я получаю значение свойства child от моего родительского компонента.
export class ParentComponent implements OnInit {
@ViewChild(ChildComponent) childReference;
parentString: string;
constructor(
private cdRef: ChangeDetectorRef,
) { }
ngOnInit() {
}
ngAfterViewInit() {
this.parentString = this.childReference.exampleChild;
this.cdRef.detectChanges();
}
В моем дочернем компоненте html у меня есть пара <mat-form-field>
входных данных:
<form [formGroup]="myForm">
<mat-form-field>
<input matInput formControlName="myInput">
</mat-form-field>
<mat-form-field>
<input matInput formControlName="myInput2">
</mat-form-field>
</form>
Но как правильно получитьзначения matInput от дочернего компонента в родительском компоненте, когда фактическая кнопка отправки находится в родительском компоненте?