I am dynamically creating checkboxes and associated dropdowns from the data i get from api ....
my html code below::
<label [for]="i" class="form-check-label fw7 h5 mb0" formArrayName="planDivList" *ngFor="let plan of planForm.controls.planDivList.controls; let i = index">
<br>
<input [name]="i" [id]="i" class="form-check-input" type="checkbox" [formControlName]="i">
{{planDivList[i].planCode}}
<label *ngIf="planDivList[i].divisions.length > 0" for="inputDiv">
Divisions
<select id="inputDiv" formcontrolName='divCtrl'>
<option *ngFor="let division of planDivList[i].divisions" Value="division.divisionCode">
{{division.divisionName}}
</option>
</select>
</label>
</label>
my dataset is
planDivList = [
{ planCode: "B3692", divisions: [] },
{ planCode: "B3693", divisions: [] },
{ planCode: "B67", divisions: [{ divisionCode: "2", divisionName: "Assisted Living " }, { divisionCode: "1", divisionName: "LILC" }] },
{ planCode: "B69", divisions: [{ divisionCode: "3", divisionName: "Four Seasons" }, { divisionCode: "2", divisionName: "Lakeside" }, { divisionCode: "1", divisionName: "Sunrise" }] }
];
ts file:
const selectedPlans = this.planForm.value.planDivList
.map((checked, index) => (checked ? this.planDivList[index].planCode : null))
.filter(value => value !== null);
console.log(selectedPlans);
Here is my stackblitz
https://stackblitz.com/edit/angular-fsgswa?file=src%2Fapp%2Fapp.component.ts
i am able to get the selected checkbox value.But How do i get the value of the respective division that is selected for that checkbox in submit button? Any help is appreciated