Les Paul
Les Paul

Reputation: 1278

AngularJS keypress event listener - NOT INPUT ELEMENT

I am trying to create a DIV that responds to keypress events, specifically the up arrow and down arrow. When the div is open, I want the window/document to respond to specific keypress events. I've seen JQuery solutions, but I'd rather not use JQuery. What's the best way to accomplish this?

Specifically, I will have different audio volume images and I want these images to change with each keypress.

Upvotes: 1

Views: 1279

Answers (2)

Les Paul
Les Paul

Reputation: 1278

The solution I found was by using vanilla JavaScript:

window.addEventListener('keydown', function(e){
    // some code here
});

Upvotes: 1

Naga Sai A
Naga Sai A

Reputation: 10975

    $scope.keypress = function($event) {
     $scope.Key = $event.keyCode
     };

You can write in the div with ng-keydown="keypress($event)" codepen URL for reference-http://codepen.io/nagasai/pen/beEQRE

    -

Upvotes: 1

Related Questions