The following works great when the enter key is released. What other options are available for the keyup
in addition to keyup.enter
?
<input #inputstring (keyup.enter)="doSomething(inputstring.value)"/>
The following works great when the enter key is released. What other options are available for the keyup
in addition to keyup.enter
?
<input #inputstring (keyup.enter)="doSomething(inputstring.value)"/>
These are the options currently documented in the tests: ctrl, shift, enter and escape. These are some valid examples of key bindings:
You can track this here while no official docs exist, but they should be out soon.
you can add keyup event like this
in Component, code some like below
Have hit the same problem today.
These are poorly documented, an open issue exist.
Some for keyup, like space:
Some for keydown
(may work for keyup too):
All above are from below links:
https://github.com/angular/angular/issues/18870
https://github.com/angular/angular/issues/8273
https://github.com/angular/angular/blob/master/packages/platform-browser/src/dom/events/key_events.ts
https://alligator.io/angular/binding-keyup-keydown-events/
If your keyup event is outside the CTRL, SHIFT, ENTER and ESC bracket, just use @Md Ayub Ali Sarker's guide. The only keyup pseudo-event mentioned here in angular docs https://angular.io/docs/ts/latest/guide/user-input.html is ENTER key. There are no keyup pseudo-events for number keys and alphabets yet.
I was searching for a way to bind to multiple key events - specifically, Shift+Enter - but couldn't find any good resources online. But after logging the keydown binding
I discovered that the keyboard event provided all of the information I needed to detect Shift+Enter. Turns out that
$event
returns a fairly detailed KeyboardEvent.There also flags for the CtrlKey, AltKey, and MetaKey (i.e. Command key on Mac).
No need for the KeyEventsPlugin, JQuery, or a pure JS binding.
This file give you some more hints, for example, keydown.up doesn't work you need keydown.arrowup:
https://github.com/angular/angular/blob/630d93150a58581a0d474ebf1befb5d09b6813c5/modules/angular2/src/platform/browser/browser_adapter.dart