I am working on a project that involves organizing food items into categories. Each item has a corresponding table entry, with a field indicating which category it belongs to. The category is represented by a Guid but displayed in a user-friendly format. Currently, every dropdown menu is part of a new form instance, causing issues with setting values separately as they all use the same form control name.
Below is a snippet of my code:
<tr *ngFor="let food of foodItems" id="{{food.Guid}}" class="alternate-row">
<td><label>{{food.foodName}}</label></td>
<td><label>{{food.foodDescription}}</label></td>
<td>
<form class="table_form" [formGroup]="tableForm" (ngSubmit)="onTableFormSubmit(tableForm.value)">
<select class="form-control" formControlName="foodCategorySelect" (change)="onTableFormSubmit(tableForm.value, food.Guid)">
<option *ngFor="let foodCategory of foodCategoryList" [value]="foodCategory.Guid" [selected]="foodCategory.Guid == food.category">
{{ foodCategory.categoryName }}
</option>
</select>
</form>
</td>
</tr>
Here is some example data from my log:
foodCategoryList
0:
Guid: "b6b64fba-1879-44fb-8a8d-1b26c2229367"
categoryName: "Starter"
[[Prototype]]: Object
1:
Guid: "ba9e3828-ddf0-4db4-bff2-2ec668d973d0"
categoryName: "Dessert"
[[Prototype]]: Object
foodList
0:
foodName: "Chicken Wings"
Guid: "ec34ce1f-5274-4d32-a17f-4a518fef9a1f"
foodDescription: "Delicious spicy chicken wings served with sauce"
category: "b6b64fba-1879-44fb-8a8d-1b26c2229367" --starter
[[Prototype]]: Object
I'm struggling to figure out how to set values individually. Any help would be greatly appreciated!