I have an HTML table with a numeric variable called statut.
The statut variable is a drop-down list, it has two values -> 1 and 9.
The method in typescript seems to be correct
public selectedBrand: any;
public onChangeStatut(statut: number) {
this.selectedBrand = statut;
this.filteredCustomer = this.customerTransferts.filter(
(item) => item.statut === this.selectedBrand
);
console.log(this.filteredCustomer);
}
I think my problem is the HTML, how to make the HTML know that it must filter a number and not a string?
<select class="form-select" style="max-width: 100px" [ngModel]="selectedBrand" (ngModelChange)="onChangeStatut($event)"> <option [value]="'1'" >1</option> <option [value]="'9'">9</option> </select>
Thank you for your help.
Advertisement
Answer
Casting this.selectedBrand to a number should work.
The + will do the trick here.
item.statut === +this.selectedBrand