I have such reactive form:
constructor(...){
this.form = this.formBuilder.group({
name: ['', Validators.compose([Validators.required, Validators.maxLength(50)])],
memes: this.formBuilder.array([
this.initMemes('TrollFace')
])
});
}
initMemes (name?) {
return this.formBuilder.group({
id: [''], name: [name]
});
}
later i can add some more memes
:
addMemes () {
const control = <FormArray>this.form.controls['memes'];
control.push(this.initMemes('anyName'));
}
and then if i get form values i get:
this.form.controls['memes'].value
- here i have array
But there is a case, when i need this this.form.controls['memes'].value
to set to an empty array, how is it possible to do?
If i set it this way:
this.form.controls['memes'].setValue([])
I got error: Must supply a value for form control at index: 0.
what i do wrong?