tellform/public/modules/forms/directives/on-enter-key.client.directive.js

21 lines
489 B
JavaScript
Raw Normal View History

2016-04-17 02:45:17 +00:00
'use strict';
2016-04-12 02:14:38 +00:00
angular.module('forms').directive('onEnterKey', ['$rootScope', function($rootScope){
return {
restrict: 'A',
link: function($scope, $element, $attrs) {
2016-04-17 02:45:17 +00:00
$element.bind('keydown keypress', function(event) {
2016-04-12 02:14:38 +00:00
var keyCode = event.which || event.keyCode;
console.log($attrs.onEnterKey);
if(keyCode === 13) {
$rootScope.$apply(function() {
$rootScope.$eval($attrs.onEnterKey);
});
event.preventDefault();
}
});
}
};
}]);