"use strict"; /** * Created by igor.samulenko on 3/5/14. */ (function () { 'use strict'; angular.module('myitsmApp') .directive('ngEnter', function () { return function (scope, element, attrs) { function keyDownKeyPressHandler(event) { if (event.which === 13 && !element.prop('readonly')) { scope.$apply(function () { scope.$eval(attrs.ngEnter, { $event: event }); }); event.preventDefault(); event.stopPropagation(); } } element.on('keydown keypress', keyDownKeyPressHandler); scope.$on("$destroy", function () { console.log("ngEnter: unbind events"); element.off('keydown', keyDownKeyPressHandler); element.off('keypress', keyDownKeyPressHandler); element.off(); }); }; }); }());