I have a form array inside a formbuilder and i am dynamically changing forms, i.e. on click load data from application 1 etc.
The issue i am having is that all the
Or you can simply clear the controls
this.myForm= {
name: new FormControl(""),
desc: new FormControl(""),
arr: new FormArray([])
}
Add something array
const arr = this.myForm.controls.arr;
arr.push(new FormControl("X"));
Clear the array
const arr = this.myForm.controls.arr;
arr.controls = [];
When you have multiple choices selected and clear, sometimes it doesn't update the view. A workaround is to add
arr.removeAt(0)
A more elegant solution to use form arrays is using a getter at the top of your class and then you can access it.
get inFormArray(): FormArray {
this.myForm.get('inFormArray') as FormArray;
}
And to use it in a template
other tags...
Reset:
inFormArray.reset();
Push:
inFormArray.push(new FormGroup({}));
Remove value at index: 1
inFormArray.removeAt(1);
Get partial object, get all errors as JSON and many other features, use the NaoFormsModule