title: How do I update an angularjs page after a scope update?
body: <p>I have written a directive that captures keyboard events, and on certain keys I update some objects in the scope. The idea is to move up and down an array and display the selected row details. The problem is the page is not updated until I do another action that updates the page. How can I force this?</p>
  
  <p>Here's the directive:</p>
  
  <pre><code>LogApp.directive("keyCapture", [function(){
      var scopeInit;
      return{
          link: function(scope, element, attrs, controller){
              scopeInit = scope
              element.on('keydown', function(e){
                  scopeInit[attrs.keyCapture].apply(null, [e]);                
              });
          }
      }
  }]);
  </code></pre>
  
  <p>Bound the template like this:</p>
  
  <pre><code>&lt;body ng-controller="logCtrl" key-capture="movePreview"&gt;
  </code></pre>
  
  <p>The controller method:</p>
  
  <pre><code>$scope.movePreview = function(e){
      if ($scope.events.length === 0)
          return;
      // Find the element 
      if (e.keyCode === 38 || e.keyCode === 40){
          console.log("Pressed %s", e.keyCode);
          var offset = 0;
          if (e.keyCode === 38 &amp;&amp; $scope.previewIndex &gt; 0)
              offset = -1;
          else if (e.keyCode === 40 &amp;&amp; $scope.previewIndex &lt; $scope.events.length -1 )
              offset = 1;
  
          $scope.previewIndex += offset;
          var eventId = $scope.events[$scope.previewIndex].uuid;
          $scope.showEvent(eventId);
          e.preventDefault();
      }
  };
  </code></pre>
  
  <p><code>$scope.showEvent(eventId)</code> will take the item with given ID and display it in another part of the page. Part that is not update until another action is performed, like clicking a button. Is it possible to force the page update?</p>
  
  <p>Here's a fiddle that reproduces: <a href="http://jsfiddle.net/gM2KF/1/" rel="nofollow">http://jsfiddle.net/gM2KF/1/</a>
  If you click on the button, the counter is updated. If you press any key, nothing shows. But you click again on the button, you see the counter has been updated by the keyboard event, but didn't show.</p>