Skip to content

Instantly share code, notes, and snippets.

@juanmanavarro
Created October 19, 2017 09:26
Show Gist options
  • Save juanmanavarro/fbf99ccb931fd286a44c0cb70a95a16a to your computer and use it in GitHub Desktop.
Save juanmanavarro/fbf99ccb931fd286a44c0cb70a95a16a to your computer and use it in GitHub Desktop.
AngularJS press enter directive
app.directive('myEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.myEnter);
});
event.preventDefault();
}
});
};
});
// markup
<input type="text" my-enter="doSomething()">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment