I want to load two dropdown one dropdown is based on another dropdown.
I am using formarray to load the form values. In my actual scenario, first i am loading values in *ngfor loop with form data(formarray). below image shows my example scenario.
Img Brief: name, age, dob are like label field. only dropdowns are form.
first i am loading values in view using *ngFor then i am loading values using form array.
here on load it should load the dropdown values. if i am selecting first dropdown. it should change the second dropdown values. on load it self i am load the data in both the dropdown using service.
component.ts
this.wholedata.foreach({ x =>
this.sampleservice.dropdown(x.firstdropdownvalue).subscribe({
this.samplevalue = res;
control.push({
dropdownvalue1: x.firstdropdownvalue,
dropdownvalue2: x.seconddropdownvalue
})
})
})
component.html
<div *ngFor="let data of datas">
//formarray codes here placed
<span>name: {{data.name}}</span>
<span>age: {{data.age}}</span>
<span>dob: {{data.dob}}</span>
<span>
<select formControlName="dropdownvalue1" (change)="changevalues($event)">
<option *ngFor="let data of dropdownvalue">{{data.values}}</option>
</select>
</span>
<span>
<select formControlName="dropdownvalue2">
<option *ngFor="let data of samplevalue">{{data.values}}</option>
</select>
</span>
<button type="submit" (click)="submitValues()">
</div>
Currently samplevalue variable values loading to last *ngfor loop because the dynamic dropdown value is changing every array based on firstdropdown so i cant able to set the value.