Skip to content

Instantly share code, notes, and snippets.

@kutyel
Forked from EpokK/ngEnter.js
Last active August 29, 2015 14:26
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 kutyel/57cd9be4c459e06e5478 to your computer and use it in GitHub Desktop.
Save kutyel/57cd9be4c459e06e5478 to your computer and use it in GitHub Desktop.
ngEnter directive if you can use submit form(https://twitter.com/ririlepanda)
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();
}
});
};
});
@kutyel
Copy link
Author

kutyel commented Jul 31, 2015

Usage: <input ng-enter="myControllerFunction()" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment