I've been wondering, what is the proper approach in preventing decimals from being entered in number inputs for angular2.
Is there a certain event or constraint I can add? When I for example just use pattern or such it will only invalidate the field but still allow typing.
What would be the proper way to prevent this, just ye olde, keyUp event and checking keystroke?
Since according to comments, asking for patterns or w/e is wrong, here is what I now implemented and works like a charm
<input (keypress)="preventInput($event)" type="number" step="1">
with preventInput as:
private preventInput(event) {
console.log(event.keyCode);
switch(event.keyCode) {
case 101: //e
case 46: //.
event.preventDefault();
break;
}
}
this won't however prevent input of . by pasting but is good enough for us.
ngPattern?