'use strict'; angular.module('forms').directive('onEnterOrTabKey', ['$rootScope', function($rootScope){ return { restrict: 'A', link: function($scope, $element, $attrs) { $element.bind('keydown keypress', function(event) { var keyCode = event.which || event.keyCode; console.log('keyCode is: '+keyCode); if((keyCode === 13 || keyCode === 9) && !event.shiftKey) { event.preventDefault(); $rootScope.$apply(function() { $rootScope.$eval($attrs.onEnterOrTabKey); }); } }); } }; }]);