Skip to content

Instantly share code, notes, and snippets.

@auxcoder
Last active August 13, 2019 16:36
Show Gist options
  • Save auxcoder/ba6b32cd503bf09a4684222574fbac20 to your computer and use it in GitHub Desktop.
Save auxcoder/ba6b32cd503bf09a4684222574fbac20 to your computer and use it in GitHub Desktop.
Simple directive, ng-enter, to invoke a function on hit the enter key.
// ng-enter="myFunction()"
app.directive('ngEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment