What is the ideal way to bind Keyboard keypress events, if you're using AngularJS?
Right now I'm setting the mapping the keyboard events inside of a controller...
ngApp.controller('MainController', function MainController($scope) {
$scope.keyEvents = function() {
if($('calculator').hasClass('open')) {
switch(e.keyCode) {
case 8:
calc.deleteDigit();
return;
case 13:
calc.equals();
*etc., etc.*
}
}
var $article = $("article");
var $articleScrollTop = $article.scrollTop();
//PageDown
if(e.keyCode == 34) {
$('article').animate({
scrollTop: ($articleScrollTop + 480 + i++)
}, 500);
}
//PageUp
if(e.keyCode == 33) {
$article.animate({
scrollTop: ($articleScrollTop - 480 - i++)
}, 500);
}
}
}
I'm beginning to think that there is a best practice when it comes to attaching keyboard events inside of an AngularJS app.
Should I be using element.bind
and setting up the keyboard events inside of the corresponding directives instead?
Thanks in advance for your help!