How can I set a FormArray of a FormGroup? I want to set definitionProperties (FormArray) of my form.
this.processorForm = this.fb.group({
propertiesSide: new FormControl(),
objectNamesSide: new FormControl(),
definitionProperties: this.fb.array([])
});
The FormArray of FormGroups:
let propertyControls: FormGroup[] = [];
propertyControls = getFormGroups(); // set definitionProperties to this
I found some code to add one by one but I'd like to set with an array rather than one value using push if it's possible:
(this.gridProcessorForm.get('definitionProperties') as FormArray).push(group)
The getFormGroups() function builds an array of groups:
createPropertyFormGroup(definitionProperty: ObjectDefinitionProperty) {
let formGroup = this.fb.group({
propertyName: definitionProperty.name,
propertyType: definitionProperty.type.name,
gridOffset: 1
});
return formGroup;
}
The setting of the FormArray is in an observable:
this.gridProcessorForm.valueChanges.subscribe(...)
createPropertyFormGroupreturn a FormGroup. I must supouse you has an array of objects[{name:'...',..},{name:'...',..}...]you can map the array:definitionProperties: this.fb.array(this.mydata.map(x=>this.createPropertyFormGroup(x)), but really I'm not very sure about your question