Good evening,
I have built a construct with reactive forms. There is a cocktail array which includes an ingredient array.
This should be projected in my reactive form called existingFlavForms.
The issue is, I can't get access to the nested ingredient formArray.
this.existingFlavForm = this.fb.group({
flavs: this.fb.array([])
});
for (let i = 0; i < this.cocktails.length; i++) {
this.existingFlavForms.push(this.fb.group({
id: [this.cocktails[i].id],
c_name: [this.cocktails[i].c_name],
mark: [this.cocktails[i].mark],
imgUrl: [this.cocktails[i].imgUrl],
ingrs: this.fb.array([
{ingr: [this.cocktails[i].ingr]}
]
)
}));
}
This is the template script, where I try to access everything.
<form [formGroup]="existingFlavForm">
<div formArrayName="flavs">
<div *ngFor="let flav of existingFlavForms.controls; let i=index">
<mat-expansion-panel class="myPanel">
<mat-expansion-panel-header>
<mat-panel-title>
<h3 class="text-info"> {{flav.value.c_name}} </h3>
</mat-panel-title>
<mat-icon class="mr-lg-3 mt-lg-2">settings</mat-icon>
<mat-icon class="mr-lg-3 mt-lg-2" (click)="deleteCocktail()">delete</mat-icon>
</mat-expansion-panel-header>
<div class="row">
<div [formGroupName]="i">
<div formArrayName="ingrs">
<p *ngFor="let ingr of flav[i].controls.ingrs.controls;">
{{ingr.i_name}}
</p>
</div>
</div>
</div>
</mat-expansion-panel>
</div>
</div>
</form>
I searched in similar questions, but can't find a proper solution. The data is there and fully initialised.
This says the browser console..
"TypeError: undefined is not an object (evaluating '_v.context.$implicit[_v.context.index].controls')"
Best regards!
I have now added a basic stackblitz, which shows the data structure in general with dummy data. https://stackblitz.com/edit/angular-l3ghac