Skip to content

Instantly share code, notes, and snippets.

@xErik
Created October 26, 2019 06:55
Show Gist options
  • Save xErik/3dd08e08307e8c5928f2e4359d94e97f to your computer and use it in GitHub Desktop.
Save xErik/3dd08e08307e8c5928f2e4359d94e97f to your computer and use it in GitHub Desktop.
Angular Sub-Components with Sub-Form input / select
@Component({
selector: 'my-comp',
template: `
<div [formGroup]="group">
<input [formControlName]="'bar'" />
</div>
`
})
export class MyComponent {
@Input() group: FormGroup;
}
@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