Skip to content

Instantly share code, notes, and snippets.

@DevEarley
Created June 21, 2017 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DevEarley/2004f47e8b7deeb38a17dc479d9f35fe to your computer and use it in GitHub Desktop.
Save DevEarley/2004f47e8b7deeb38a17dc479d9f35fe to your computer and use it in GitHub Desktop.
Do some action on enter. Angular directive.
angular
.module("on-enter", [])
.directive("onEnter", function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if (event.which === 13) {
scope.$apply(function () {
scope.$eval(attrs.onEnter);
});
event.preventDefault();
}
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment