I am trying to set up a simple FormArray in Angular and am having a hard time getting it to work.
What am I missing?
documentationForm: FormGroup;
documentationArray: FormArray;
defaultDocumentation = 1;
ngOnInit() {
this.documentationForm = this.formBuilder.group({
id: this.formBuilder.array([])
});
}
When a file is added to uploader component, I am calling the following :
fileAddedToQueue(file) {
this.documentationArray = this.documentationForm.get('id') as FormArray;
this.documentationArray.push(this.addDocumentType());
}
private addDocumentType(): FormGroup {
return this.formBuilder.group({ id: this.defaultDocumentation });
}
I put a bunch of console.log and it seems to be working as expected but I cannot get it working with my HTML.
<div formArrayName="id" *ngFor="let file of documentationForm.get('id').controls; let i = index" [formGroupName]="i">
test
</div>
I get the following :
Unhandled application error. Error: Cannot find control with name: 'id'
What am I doing wrong? Everything seems to be correct from what I can see.