keypress
event not firing with enter key in angular 2, following is the html and angular 2 code:
HTML
<input [(ngModel)]="filters[i]" type="number" size="30" pInputText (keypress)="filterByField($event, col.field, fieldType.TEXT)" class="{{'input-'+col.field}}" title="Only numbers are allowed" />
Angular 2
filterByField(event, field, fieldType){
console.log(event)
if(fieldType === this.fieldType.DD){
event.originalEvent.stopPropagation();
this.resetFilterBy(event.value, field);
this.loadData(null, true);
}
else if(fieldType === this.fieldType.TEXT){
let charCode = (event.which) ? event.which : event.keyCode;
console.log(charCode)
if (charCode == 101 && field == this.fields.TASKID.field){
event.preventDefault();
return false;
}
if((charCode === 13 && event.target.value.trim() !== "") || (charCode === 8) || (charCode === 46)) {
let filterValue = event.target.value;
this.resetFilterBy(filterValue, field);
this.loadData(null, true);
}
}
}