In my Angular 11.2.6 project, I have a form with three child components, all of which take user inputs.
I want to attach formControls to all of these child components and make the formGroup in my parent component. But I don't know how to bind the inputs in my child components to the formgroup in my parent component.
This is my parent component html:
<form class="form__main" (ngSubmit)="onSubmit()">
<h2>{{ 'choose_cryptocurrency' | translate }}</h2>
<currency-selector></currency-selector>
<coin-amount-input></coin-amount-input>
<button class="button__submit--order" mat-raised-button color="primary">
{{ 'submit_order' | translate }}
</button>
</form>
and this is my parent component ts:
exchangeBuyForm = new FormGroup({
buyingCoin: new FormControl(''),
payingCoin: new FormControl(''),
});
and this is my child component html (coin amount input):
<div class="wrapper__input">
<mat-label>input currency</mat-label>
<mat-form-field class="input__currency" appearance="fill">
<input
type="text"
name="formattedNumberInput"
class="mat-input-element"
#formattedNumberInput
[ngModel]="formattedValue"
/>
</mat-form-field>
</div>
Please note that I only added one of the child components here for increased readability. I assume all of them work the same.