Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html ng-app=App>
<head>
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-controller=Ctrl>
  <input ng-repeat="entry in entries" value={{entry}} on-up="focusPrev(entry)" on-down="focusNext(entry)">
</body>
</html>
 
var app = angular.module('App', []);
// Apply given piece of code (as attribute) when the up arrow hit event is
// triggered.
app.directive('onUp', function () {
  return function (scope, elem, attrs) {
    elem.bind('keyup', function (e) {
      if (e.keyCode == 38)
        scope.$apply(attrs.onUp);
    });
  };
});
// Apply given piece of code (as attribute) when the down arrow hit event is
// triggered.
app.directive('onDown', function () {
  return function (scope, elem, attrs) {
    elem.bind('keyup', function (e) {
      if (e.keyCode === 40)
        scope.$apply(attrs.onDown);
        console.log("on down");
    });
  };
});
// Main Controller
function Ctrl($scope) {
  $scope.entries = [
    'apple',
    'ball',
    'cow'
  ];
  
  $scope.focusNext = function (entry) {
    console.info('Focus the entry after', entry);
  };
  
  $scope.focusPrev = function (entry) {
    console.info('Focus the entry before ', entry);
  };
}
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers