ngKeyup, ngKeydown and ngKeypress

24 views
Skip to first unread message

Dawid Anonim

unread,
Jul 5, 2016, 8:24:34 AM7/5/16
to AngularJS
Hello

why ngKeyup, ngKeydown and ngKeypress have exactly the same documentation but they don't work the same? example:

<div>
<textarea ng-keydown="keyEvent = $event"></textarea>
</div>
<div>
<strong>Key code:</strong> {{ keyEvent.keyCode }} <br>
</div>

if you put ng-keydown and ng-keyup it works if u put ng-keypress it dosen't work
anyone know why?

AngularJS v.1.5.7

Lucas Lacroix

unread,
Jul 5, 2016, 9:25:45 AM7/5/16
to ang...@googlegroups.com
I don't think this is an Angular issue. KeyUp and KeyDown events are different from KeyPress events. KeyUp/Down give you key codes while KeyPress gives you character codes - sometimes these are the same, sometimes they are not. The way in which the different browser have implemented the events differs as well. Some libraries, like jQuery, normalize the different browser implementations - not sure the Angular does this.

My suggestion would be to use the json pipe to look at the keyEvent object like:
<string>Event:</strong>{{ keyEvent | json }}<br>



--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
Lucas Lacroix
Computer Scientist
System Technology Division, MEDITECH

Dawid Anonim

unread,
Aug 4, 2016, 5:13:29 AM8/4/16
to ang...@googlegroups.com
Thank you very very much for your help :)

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/Q2jjKBqF3Yc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages