Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle Tab event

Tags:

angular

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')" /> 
like image 893
freeNinja Avatar asked Feb 15 '17 04:02

freeNinja


People also ask

How do you press a tab key?

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.

How to handle Tab key event in JavaScript?

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.


2 Answers

 <input (keydown.Tab)="onKey($event)"> 
like image 99
Günter Zöchbauer Avatar answered Sep 28 '22 01:09

Günter Zöchbauer


<input (keypress)="someFunction($event.target.value)"/> 
like image 36
Yoav Schniederman Avatar answered Sep 28 '22 02:09

Yoav Schniederman