There are so many answers to this question, but I cannot figure out how to solve two problems. After research, I build a very simple directive.
.directive('keypressEvents', function ($document) {
return {
restrict: 'A',
link: function () {
$document.bind('keypress', function (e) {
alert(e.keyCode);
});
}
}
});
The first problem is more like a question, if I did this angular.service('myService', myServiceFunction);, would it work globally? Secondly, some keys do not work, like ESC, ctrl arrows, etc. I am working on this CODEPEN
source
share