Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AngularJS ngKeyup on a div rather than an input

I've set up a Plunker with some example code: http://plnkr.co/edit/upExTHzpkwtZ45mdikFr?p=preview

The very succinct question is: I'm trying to use AngularJS' ng-keyUp directive. In the docs I've only seen is used on an input, although I'm trying to capture keypresses anywhere on the page rather than just inside an input box. Like so:

// view

<div ng-keyup="keyPress($event)">
     // The bulk of my controller's view goes in here
</div>

// inside controller

$scope.keyPress = function(e){
     console.log(e);
}

Again, see the Plunker above for an example. Currently, it doesn't work at all and nothing is logged. How can I get it to work properly?

like image 596
JVG Avatar asked Nov 11 '13 06:11

JVG


1 Answers

Try to give the div element focus, or use tabindex="1"

like image 102
oori Avatar answered Oct 27 '22 09:10

oori