30 comments on “AngularJS Detect Enter Key – ngEnter

  1. I couldn’t get it to work. I even tried ngEnter=”alert(‘hi’);” and no joy. Do you have a JsFiddle on this? Could there be an Angular library that has been split out that is needed?

    • I shall clarify what I mean: I’m using a directive that doesn’t have a controller, and it’s a big one, if I try to add a controller myself, I’ll probably mess up stuff. But it has events, and I want to raise one of those events on Enter key press. Any idea how to do that?

  2. Works fine, thanks. Are there cases where it can create a security hole/exploitation because of ‘scope.$eval’ or is it safe to use?

  3. Just wanted to say that I used this in a production environment. We had menu items that you can tab along even if disabled, but still press enter. I modified it a little bit to check for the element.classList.disabled and it worked a treat.

  4. Great but as of now (2016-02-25), AngularJS has a built in directives such as keypress, keyup and keydown.
    You can achieve the same with ng-keyup=”$event.keyCode==13 && myFunction()” without a need for custom directives.

Leave a Reply