I am developping a datalist facility. On keyup event of the input, I am calling a get request that send back an array of string which populate the datalist
<input type="text (keyup)="findPostalCode($event)" list="codePostalId" />
<datalist id="codePostalId">
<option *ngFor="let code of postalCodeList">{{code}}</option>
</datalist>
Here is the component function that manages keyup event
findPostalCode(event: any) {
event.stopPropagation();
event.preventDefault();
this.postalCodeList = [];
let text = event.target.value;
if (text != null && text.length > 2) {
this.produitImmobilierService.getPostalCodes(text).subscribe( result => {this.postalCodeList = result; });
}
}
And the keyup event trigger twice when I enter a character into the input.