I have an event that fires on key up like this.
value: number;
onKeyUp(event: KeyboardEvent) {
this.value = this.input.nativeElement.value;
console.log("typo", typeof (this.value));
}
For some reason, the value stored is a string not a number. I've tried using syntax like this to no avail.
this.value = this.input.nativeElement.value as number;
Instead of that, I had to use the JS hack from the past, i.e. the unary plus operator like so.
this.value = +this.input.nativeElement.value;
Is there a more proper approach to make sure that my input provides a number? Or am I already doing it kinda right?
The markup provides no useful info, probably, but just in case, here it is.
<input #input
value="{{value}}"
(keyup)="onKeyUp($event)"
(keydown.Tab)="onKeyUp($event)">