angular2 - validating FormControlName in child component of parent FormGroup

前端 未结 2 1531
醉梦人生
醉梦人生 2020-12-21 03:20

I have an angular component corresponding a form/page that is generating an indeterminate amount of child components, each representing an individual field, and I would like

2条回答
  •  生来不讨喜
    2020-12-21 03:21

    The problem here is, that it is not possible to have the same form control name multiple times in one form group.

    You need to declare an own form group for each child component and then you can iterate over it in the parent component based on your reference attribute. You can get each child form control with the directive component method FormGroupDirective.getControl(controlName) as you can see in documentation: https://angular.io/docs/ts/latest/api/forms/index/FormGroupDirective-directive.html

提交回复
热议问题