How can I handle a Tab keypress
event in Angular 2?
I took this from the Angular docs to get the keyCode
. It works well when I press the other keys, but when I press Tab nothing happens.
import { Component } from '@angular/core'; @Component({ selector: 'my-app', template: `<input (keyup)="onKey($event)"> <p>{{values}}</p>` }) export class AppComponent { values = ''; onKey(event: any) { this.values += event.keyCode+ ' | '; } }
Also, is this the correct way to do it in Angular 2?
<input ng-keydown="($event.keyCode == 9) && signal('something')" />
You can find the tab key on the left side of the keyboard, just above the caps lock key and to the left of the Q key. You can recognize the tab key by its two arrows going in opposite directions and pointing towards a line, one above the other.
Q: How to call a function when pressing the tab key in JavaScript? Answer: Add an event listener to the document and match the keycode with the tab keycode. If the condition is true then call function. Do comment if you have any doubts or suggestions on this JS event topic.
<input (keydown.Tab)="onKey($event)">
<input (keypress)="someFunction($event.target.value)"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With