everything good? I'm working with FormArray and I have the following problem, when trying to get the value of the category it always returns the same value because as it's a formArray the id="category" is fixed. I can currently leave the id dynamic like this: id:"category"+i. But I am not therefore doing a get on this id:"category"+i value. dynamically. The problem is how to get this value dynamically. grateful in advance
Component
getCategory() {
this.nameList = []
const value = (<HTMLInputElement>document.getElementById("category")).value
console.log(this.nameList)
this.initcategory(value)
}
initcategory(value) {
console.log(value)
const totalResults = 0;
const searchModel = {
text: '',
status: '',
};
this.feedstockService.getFeedstock(totalResults, searchModel)
.subscribe(response => {
const feedstocks = response.results.filter(x => x.category === value)
feedstocks.forEach(feedstock => this.nameList.push(feedstock.name))
})
}
HTML
<ng-container [formGroup]="feedstockForm">
<ng-container formArrayName="feedstock">
<accordion [closeOthers]="oneAtATime" *ngFor="let fcFeedStock of feedstockForm.get('feedstock')?.controls; let i = index">
<accordion-group heading="{{ fcFeedStock.get('position').value }} / {{ fcFeedStock.get('category').value }}" [formGroupName]="i">
<div>
<i class="material-icons close-category" (click)="removeFeedstockCategory(i)">
close
</i>
</div>
<div class="divide-section">
<div class="first-column">
<div class="header-section options">
<span>ADICIONAR COMPONENTE</span>
<i class="material-icons" (click)="addFeedstockComponent(i)">
add
</i>
</div>
<div class="form-group">
<label for="category">CATEGORIA</label>
<select class="form-control" formControlName="category" id="category" (onChange)="getCategory()" (blur)="onCountryChange($event.target.value)">
<option value="" selected ></option>
<option *ngFor="let cat of categories" [value]="cat.value">
{{cat.viewValue}}
</option>
</select>
</div>