AngularJS - ng-keypress does not work for event input

In my project, ng-keypress does not work for "Enter Key" from all places. From some places it works fine, but from other places it works for all keys except "Enter Key".

Here I call the test () method on ng-keypress.

<div class="actions">
    <div class="ui approve button red" data-ng-click="test()" id="confirm-yes" tabindex="8" ng-keypress="test()">Yes</div>
    <div class="ui cancel button" data-ng-click="test()" id="confirm-no" tabindex="7" ng-keypress="test()">Cancel</div>
</div>

From the test method, I just show the key code. I could see the keyboard code correctly for all other keystrokes except Enter.

$scope.test = function () { 
            alert('test called'+event.keyCode);
        }

I have looked through many StackOverflow articles and I am sure that its syntax is correct, but I am completely confused by its strange behavior.

Any idea why ng-keypress doesn't work for input and works for all other keys.

+4
source share
4 answers

, <div> <button>, . Button tag .

<div class="actions">
    <button class="ui approve button red" data-ng-click="test()" id="confirm-yes" tabindex="8" ng-keypress="test()">Yes</button>
    <button class="ui cancel button" data-ng-click="test()" id="confirm-no" tabindex="7" ng-keypress="test()">Cancel</button>
</div> 
0

- , event.stopImmediatePropagation():

.

0

test() ng-click ng-keypress,

   <div class="ui approve button red" data-ng-click="test()" id="confirm-yes" tabindex="8" ng-keypress="testcheck()">Yes</div>
    <div class="ui cancel button" data-ng-click="test()" id="confirm-no" tabindex="7" ng-keypress="testcheck()">Cancel</div>
0

ngKeypress. , Angular 'Enter'.

ngKeydown. 'Enter' .

0

Source: https://habr.com/ru/post/1688795/


All Articles