Skip to content

Instantly share code, notes, and snippets.

@fisshy
Last active August 29, 2015 14:01
Show Gist options
  • Save fisshy/6d61500cd226b3f12b32 to your computer and use it in GitHub Desktop.
Save fisshy/6d61500cd226b3f12b32 to your computer and use it in GitHub Desktop.
Execute function when pressing enter
angular.module('moduleName')
.directive('ngEnter', function () {
return {
scope: {
ngEnter: '&'
},
link: function ($scope, $element) {
$element.bind("keydown keypress", function (event) {
if (event.which === 13) {
$scope.ngEnter();
event.preventDefault();
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment