Created
October 26, 2019 06:55
-
-
Save xErik/3dd08e08307e8c5928f2e4359d94e97f to your computer and use it in GitHub Desktop.
Angular Sub-Components with Sub-Form input / select
This file contains 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
@Component({ | |
selector: 'my-comp', | |
template: ` | |
<div [formGroup]="group"> | |
<input [formControlName]="'bar'" /> | |
</div> | |
` | |
}) | |
export class MyComponent { | |
@Input() group: FormGroup; | |
} |
This file contains 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
@Component({ | |
selector: 'my-app', | |
template: ` | |
<form [formGroup]="reactiveFormGroup"> | |
<input formControlName="foo" /> | |
<my-comp **[group]="reactiveFormGroup"**></my-comp> | |
</form> | |
form value: {{ reactiveFormGroup.value | json }} | |
` | |
}) | |
export class AppComponent { | |
reactiveFormGroup = new FormGroup({ | |
foo: new FormControl('default foo'), | |
bar: new FormControl('default bar') | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment