I am encountering an issue with capturing the pressed key in my basic ng2 application.
My goal is to determine which key was pressed each time.
To achieve this, I set up a simple markup with an input field that detects keyup events to track the pressed key (letter):
<input type="text" class="input-letter" id="input-letter" #box (keyup)="onKey(box.value)">
<div>
{{key}}
</div>
While this method is functional, I would like to only display and capture one key value at a time, clearing previous entries. Currently, all keys/letters are appended to the existing key variable.
I attempted to create a clearKey()
method to reset the key value, but it does not seem to be working as intended:
clearKey(): void{
this.key = null; // I even tried ' ' instead of null
}
onKey(value: string): void {
this.clearKey();
this.key = value;
}
Any suggestions on what I may be doing incorrectly are greatly appreciated. Thank you.