- Componente Filho
typescript
export class ChildComponent implements OnInit {
public childGroup: FormGroup;
constructor(private fb: FormBuilder) {}
ngOnInit() {
this.childGroup = this.fb.group({
control1: [''],
control2: ['', [Validators.required]],
});
}
}
- Componente Pai
html
<app-child-component></app-child-component>
typescript
export class FatherComponent implements AfterViewInit {
@ViewChild(ChildComponent)
childComponent: ChildComponent;
public fatherGroup: FormGroup;
constructor() {}
ngAfterViewInit() {
// Faz uma cópia do grupo no componente filho no grupo do componente pai
this.fatherGroup = this.childComponent.childGroup;
}
}