Skip to content

Instantly share code, notes, and snippets.

@zhang-ning
Created September 29, 2014 07:25
Show Gist options
  • Save zhang-ning/1a42ad497e4cf81d4cb4 to your computer and use it in GitHub Desktop.
Save zhang-ning/1a42ad497e4cf81d4cb4 to your computer and use it in GitHub Desktop.
angular
/*
This directive allows us to pass a function in on an enter key to do what we want.
*/
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();
}
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment