Jyoti Shankar Chaubey
Jyoti Shankar Chaubey

Reputation: 23

Not able to Predict Input from Scanner or Keyboard in Angular

I am working with angular 6. I just got a problem. i have a text-box and a submit button. i want to add a functionality.Input into text box will be either by keyboard or by Bar-code scanner. after input all text the button should be submit automatically in case of bar-code scanner. If i go with OnChange or Keypress event then on every character the button is going to submit in both cases. (Keyboard,Barcode scanner).

I have searched also for if i get the event to predict the scanner input or keyboard input then i will do rest of things.

Upvotes: 0

Views: 810

Answers (1)

Thilina Koggalage
Thilina Koggalage

Reputation: 1084

Try something like this.

In you html add keyup event.

<input type="text" (keyup)="onKeyUp()">

Then call your submit function after a timeout like this.

onKeyUp() {
    lsetTimeout(() => {
        submitFunction();
    }, 3000);
}

Upvotes: 1

Related Questions