Reputation: 1278
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
Reputation: 1278
The solution I found was by using vanilla JavaScript:
window.addEventListener('keydown', function(e){
// some code here
});
Upvotes: 1
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