Posts

Showing posts from January 8, 2019

collecting user keyevent input for 2 secs and then clear it

Image
0 I have private userInputTimer; private userInputText = ''; private handleEvent(event: KeyboardEvent): void { if((keyNum >= 48 && keyNum <= 90) || (keyNum >= 96 && keyNum <= 105)){ this.userInputText = (this.userInputText) ? this.userInputText : ''; this.userInputText = this.userInputText + keyCode; clearTimeout(this.userInputTimer); this.setUserInputClearTimer(); } setUserInputClearTimer(){ this.userInputTimer = setTimeout(() => { this.userInputText = ''; }, 500); } Using this code, I can delete the text which the user has entered consecutively after 500 ms. How can I achieve this behavior using RxJs debounce. I would really appreciate some help angular typescri