Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

add ng-keyup and ng-keydown #1035

Closed
carpasse opened this issue Jun 11, 2012 · 12 comments
Closed

add ng-keyup and ng-keydown #1035

carpasse opened this issue Jun 11, 2012 · 12 comments

Comments

@carpasse
Copy link

Can you guys please add the ng-keydown and ng-keydown directives

I Think it would be extremely easy to add both directives to angular since you already have this generic mechanism to create 'event directives'

The only think to do is on line 12294 of angular-1.0.0rc10.js

    'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave'.split(' '),

add the two new events

    'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup'.split(' '),

I´ve tryied on my machine and it works perfectly.

Thanks for the effort on angular.

Carles.

@IgorMinar
Copy link
Contributor

Hi Carles, can you briefly describe how you use these events? We haven't had the need for them because we always rely on model data-binding.

@carpasse
Copy link
Author

Hi Igor

My reason for asking for this two directives is to improve code readability.

I would like to use this 'ng-keyup' on a custom auto complete directive that needs to connect with the server every time a new character is typed.

I could rely on data binding (scope.$watch) but, don´t you think it would make the html more readable to use ng-keyup' on the template of the directive?

If a developer sees a input tag like '', he would never expect that everytime you type a character, you are connecting to the server to retrieve all the matching names.

But if instead you have '', it´s much easier to understand what´s happening.

I also think that's a little confusing to have a ng-mouseup directive and not a ng-keyup directive. For a new developer that comes to angular and doesn´t understand the data binding completely, it can be frustrating (or at least that´s what my collegues told me when I told them to use scope.$watch instead).

Carles.

@severb
Copy link

severb commented Jun 19, 2012

Navigating trough the autosuggestion list using arrow keys may be a usecase. It would also be nice to be able to dispatch based on keycode values or friendlier aliases.

@pkriens
Copy link

pkriens commented Jul 27, 2012

I think it would be very nice because I'd like to execute an action after a user has hit the enter key in an input box

@ciddan
Copy link

ciddan commented Sep 27, 2012

Another use case I'm implementing right now is keyboard shortcut keys in a web application. Feels very hack-y to do pure jQuery event handling of keydown/keyup in my directive - would much prefer that these two events were defined as directives.

@BernhardPosselt
Copy link

Im doing a chat application and i want to submit the message on enter when the user hits it in the textarea. If he hits shift + enter i want to add a linebreak in the textarea.

@ProLoser
Copy link
Contributor

Since this will not be going into the core, anyone coming across this ticket and still wants this functionality:

Go checkout AngularUI Keypress

marknadig added a commit to KonaTeam/angular.js that referenced this issue Jan 28, 2013
@ProLoser
Copy link
Contributor

Is there a reason that ng:keypress was not added? Seems like you're stopping just before the finish line...

@marknadig
Copy link
Contributor

Hi Dean, oversight really. No reason could't add as additional PR.

@ProLoser
Copy link
Contributor

I've already got it in AngularUI. It will be up to someone else to add this.

@klebba
Copy link

klebba commented Feb 26, 2013

+1 or ng:keypress -- no rational reason to omit right?

@marknadig
Copy link
Contributor

done #2101

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants