Multiple child component inside form - Angular 2

試著忘記壹切 提交于 2019-11-30 16:08:28

You need to use Input() and pass that sub-FormGroup to the child. I changed it a bit here and made the group named useraccount instead of useracc to separate the control from the group:

Your sub group for useraccount in your parent:

  ...
  useraccount: this.formBuilder.group({
    useracc: '',
  })
  ...

So, the related child component tag in the parent should look something like this:

<app-useracc [useraccount]="formDetail.controls.useraccount"></app-useracc>

And then add input in your child component:

@Input() useraccount: FormGroup;

and template could look like this:

<div [formGroup]="useraccount">
  <input formControlName="useracc">
</div>

Working sample

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!