Skip to content

Instantly share code, notes, and snippets.

@billyxs
Last active August 29, 2015 14:02
Show Gist options
  • Save billyxs/55a3be71b5c86d9d4e9a to your computer and use it in GitHub Desktop.
Save billyxs/55a3be71b5c86d9d4e9a to your computer and use it in GitHub Desktop.
Angular - On Enter Keypress Directive
app.directive('xs-enter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
event.preventDefault();
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.xsEnter);
});
}
});
};
});
<input type="text" data-xs-enter="yourEvent()">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment