Forked from canabady/Linking Parent-Component-FormGroup-with-Child-Component-FormControlName
Created
March 19, 2020 07:24
-
-
Save maheshbabu/4a13d4c1d13d47a271c3315668549a46 to your computer and use it in GitHub Desktop.
Connecting parent component 'formGroup' with child component 'formControlName'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment