Created
October 19, 2017 09:26
-
-
Save juanmanavarro/fbf99ccb931fd286a44c0cb70a95a16a to your computer and use it in GitHub Desktop.
AngularJS press enter directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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