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
JavaScript
x
9
1
public selectedBrand: any;
2
public onChangeStatut(statut: number) {
3
this.selectedBrand = statut;
4
this.filteredCustomer = this.customerTransferts.filter(
5
(item) => item.statut === this.selectedBrand
6
);
7
console.log(this.filteredCustomer);
8
}
9
I think my problem is the HTML, how to make the HTML know that it must filter a number and not a string?
JavaScript
1
5
1
<select class="form-select" style="max-width: 100px" [ngModel]="selectedBrand" (ngModelChange)="onChangeStatut($event)">
2
<option [value]="'1'" >1</option>
3
<option [value]="'9'">9</option>
4
</select>
5
Thank you for your help.
Advertisement
Answer
Casting this.selectedBrand
to a number should work.
The +
will do the trick here.
JavaScript
1
2
1
item.statut === +this.selectedBrand
2