Skip to content

Instantly share code, notes, and snippets.

@tarex
Created September 11, 2014 12:22
Show Gist options
  • Save tarex/5cc5c5a79c665a9e1631 to your computer and use it in GitHub Desktop.
Save tarex/5cc5c5a79c665a9e1631 to your computer and use it in GitHub Desktop.
Press Enter to do something
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();
}
});
};
});
<div ng-app="" ng-controller="MainCtrl">
<input type="text" ng-enter="doSomething()">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment