frenchtoastfella
frenchtoastfella

Reputation: 45

AngularUI ui-keypress for any button?

Alright so, what I need is a way to forward keypress (or keydown, whatever) event that occurred on textarea element, and what I've tried to do is this:

<div id="wrapper" ng-controller="MyTestCtrl">
    <div id="text" ng-click="DivClick()">
        <ul>
            <li ng-repeat="item in items">
                <textarea ng-click="InnerClick()" ui-keypress="TextKeypress()" autofocus></textarea>
            </li>
        </ul>
    </div>
</div>

But it seems to be acting funny and I want to avoid using any particular key-code since I need it to updates that textarea's height every time a user types something in it (which is what TextKeypress functions is doing).

Upvotes: 2

Views: 2113

Answers (2)

ProLoser
ProLoser

Reputation: 4616

You could use uiEvent: <textarea ui-event=" { keypress: 'whatever($event)' } ">

UPDATE:

The core now include ng-keypress too! (no idea which version)

Upvotes: 4

frenchtoastfella
frenchtoastfella

Reputation: 45

Alright, I've overcome this by creating a custom directive that suits my needs and I've bound that directive to the element with 'keypress'. Something like this:

.directive('mydKeypress', function(){
    return function(scope, elm, attrs){
        elm.bind('keypress', function(e){
            //Whatever code;
            alert('it bloody works!');
        });
    };
});

Upvotes: 1

Related Questions