0
Hello, I am trying to create a reusable form Component using Reactiveforms. Like when I want to use a form, I will just pass an array of my inputs from that form.
But I’m not sure if it’s really possible. In my case I’m stuck here:
export class FormularioShared implements OnInit{
formulario: FormGroup;
@Input() inputs: InputsModels[];
constructor(private formBuilder: FormBuilder){}
ngOnInit(){
this.formulario = this.formBuilder.group({
[this.inputs[0].formControlName]: this.formBuilder.control('', Validators.required),
});
}
}
When I don’t know how to fill in my input array to create the formbuilder Controls! Would you like to know if this is really possible?? Thank you in advance.
I didn’t quite understand your doubt, but I asked a question on SO-En that I think might be what you want, see: How to add a Child Component Within Parent Component using React Forms?
– Marconi