Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
155
rated 0 times [  159] [ 4]  / answers: 1 / hits: 26308  / 10 Years ago, sat, august 23, 2014, 12:00:00

I'm trying to create an interaction similar to the konami code up,up,down,down,a,b,a,b, enter -> something happens.



Is it possible to listen for arrow keyspress using ng-keypress? it seems to not work?



html:



input( ng-keypress='changed($event)'  )


Js



$scope.changed = (evt) ->
console.log(evt)


this will not log out arrow key events?



Do I have to roll out my own listeners on the window? if so how can I achieve this in angular?


More From » angularjs

 Answers
169

DEMO



$scope.key = function($event){
console.log($event.keyCode);
if ($event.keyCode == 38)
alert(up arrow);
else if ($event.keyCode == 39)
alert(right arrow);
else if ($event.keyCode == 40)
alert(down arrow);
else if ($event.keyCode == 37)
alert(left arrow);
}


EDIT



Change it from ng-keypress to ng-keydown. DEMO



<input ng-keydown=key($event) />

[#69677] Thursday, August 21, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarvisjovannia

Total Points: 127
Total Questions: 123
Total Answers: 101

Location: Netherlands
Member since Mon, Jun 7, 2021
3 Years ago
;