I have two selects, Category and Subcategory, on subcategory select i am filtering data based on category value.
Also if user wants he/she can add new row and add new data.
// create another field for categories
createCat(array: any, form: any) {
let formgroup = this.fb.group({
carPartCategory: ['', Validators.required],
carPartSubCategory: ['', Validators.required],
quantity: ['', Validators.required],
comment: [''],
});
this.formArrCat.push(formgroup);
}
my issue is that: if there is more then 1 row and i select value in category select, all subcategory selects change value.
// get car part subcategory
getCarPartsSubCategory(event: any) {
let value = event.value;
this.inputValue = [];
console.log(value);
this.inputValue = [...this.inputValue, ...value.carPartSubCategories];
this.filteredcarPartsSub.next(this.inputValue);
}
how can i make value stay same in other formgroups when i am chooosing it in different row?
here is my stackblitz
.html
<mat-form-field appearance="fill" class="nusx">
<mat-label>Choose Category</mat-label>
<mat-select #multiSelect formControlName="carPartCategory"
(selectionChange)="onChange($event); getCarPartsSubCategory($event)">
<mat-option>
<ngx-mat-select-search [formControl]="carPartsMultiFilterCtrl" [placeholderLabel]="'search...'"
[noEntriesFoundLabel]="'not found'">
</ngx-mat-select-search>
</mat-option>
<mat-option *ngFor="let item of filteredcarParts | async" [value]="item">{{item.name}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="fill" class="nusx">
<mat-label>Choose Subcategory</mat-label>
<mat-select #multiSelect formControlName="carPartSubCategory">
<mat-option>
<ngx-mat-select-search [formControl]="carPartsSubMultiFilterCtrl"
[placeholderLabel]="'search...'" [noEntriesFoundLabel]="'not found'">>
</ngx-mat-select-search>
</mat-option>
<mat-option *ngFor="let item of filteredcarPartsSub | async; let i = index;" [value]="item">
{{item.name}}
</mat-option>
</mat-select>
</mat-form-field>