title: Binding keyboard events in AngularJS
body: <p><strong>What is the ideal way to bind Keyboard keypress events, if you're using AngularJS?</strong></p>
  
  <p>Right now I'm setting the mapping the keyboard events inside of a controller...</p>
  
  <pre><code>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);
      }  
    }
  }
  </code></pre>
  
  <p>I'm beginning to think that there is a best practice when it comes to attaching keyboard events inside of an AngularJS app.</p>
  
  <p>Should I be using <code>element.bind</code> and setting up the keyboard events inside of the corresponding directives instead?</p>
  
  <p>Thanks in advance for your help!</p>