In my code, I'M trying to filter a list of elements when an option is selected from a combobox. My code is below. Right now, the code doesn't have any errors, but I couldn't succeed on filtering the list. What should I do?
HTML:
<mat-form-field appearance="outline" fxFlex fxFlex.gt-sm="50" class="pr-4">
<mat-label>Document Type</mat-label>
<mat-select [(ngModel)]="sourceType" (ngModelChange)="searchTransaction()">
<mat-option *ngFor="let dp of sourceTypeList" [value]="dp">
{{dp.Name}}
</mat-option>
</mat-select>
</mat-form-field>
TS:
sourceTypeList: IBasicModel[];
sourceType: IBasicModel;
stockTransactionList: IStockTransaction[] = [];
searchTransaction() {
if (this.stockTransactionList && this.stockTransactionList.length > 0) {
let stockTransactionSearchData: IStockTransaction[] = [
...this.stockTransactionList,
];
//FILTER FOR SOURCE TYPE
if(this.sourceType){
stockTransactionSearchData = stockTransactionSearchData.filter((x) => x.SourceType.Id);
}
//Default
this.dataSourceStockTransactions.data = [...stockTransactionSearchData,];
}
}