1

I use Angular and i don't found who detect if on pressing key out of an input... I try this :

<div (keyup)="moveSlider($event)"></div>

But it does not work

If you can help me! :p (Sorry for my bad english)

Kérian Pelat
  • 121
  • 2
  • 12
  • 1
    Do you have an `input` element? A div is not an input. – ConnorsFan Jan 11 '18 at 21:33
  • He wants to detect when the key is pressed outside of the input, that's why he's not placing the listener on the input. By the way you can do it, as I said in my answer, by listening for the event on the ``, it should work. – SyncroIT Jan 11 '18 at 21:35
  • Your element must be focused for an event to be detected. You have an empty div, which will not get focused and will not be able to detect the key up event. Attach the detector to a higher level dom node and you should be good to go. – Z. Bagley Jan 11 '18 at 21:38
  • You should get what you want in [this answer](https://stackoverflow.com/a/38974186/1009922). You can test it in [this stackblitz](https://stackblitz.com/edit/angular-6pew3t). – ConnorsFan Jan 11 '18 at 22:33

1 Answers1

0

You can't listen for a keyup event outside of an <input> or a focusable element, so you have to listen it on the <body> element (for the whole document).

I wrote an example script on jQuery, you can see it here: https://jsfiddle.net/c5stv2a4/

SyncroIT
  • 1,510
  • 1
  • 14
  • 26