Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save canabady/3e4b96717057411510f2dc8c7ddfdaf7 to your computer and use it in GitHub Desktop.
Save canabady/3e4b96717057411510f2dc8c7ddfdaf7 to your computer and use it in GitHub Desktop.
Connecting parent component 'formGroup' with child component 'formControlName'
Connecting parent component 'formGroup' with child component 'formControlName'
In the Parent component template
================================
<form [formGroup]="recipeForm">
<app-recipe-name [parent]="recipeForm"></app-recipe-name>
</form>
In the Child component, under the class add
===========================================
@Input() parent: FormGroup;
In the Child component template
===============================
<mat-input-container fxFill [formGroup]="parent">
<input matInput placeholder="Recipe Name" [matAutocomplete]="recipeAutocomplete" formControlName="recipeName">
</mat-input-container>
Now 'recipeName' is accessible from parent
Ref URL: https://toddmotto.com/component-architecture-reactive-forms-angular
@JosephWesker
Copy link

JosephWesker commented Apr 12, 2022

How amazing is this, watched a 10 min tutorial, no success, but here in 20 lines I found the references what I need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment