Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger function on enter in angular input field [duplicate]

is there a way to trigger event when clicking on ENTER key in the input field? I found a directive that someone suggested to use, but I wonder if there is a simple way to do it.

I am using angular 1.3.

like image 441
orikoko Avatar asked Nov 20 '14 13:11

orikoko


People also ask

How do you check if Enter key is pressed in angular?

Check the event. And the following JavaScript code to detect whether the Enter key is pressed: const input = document. querySelector("input"); input. addEventListener("keyup", (event) => { if (event.

What is keypress event in angular?

(keyup) is an Angular event binding to respond to any DOM event. It is a synchronous event that is triggered as the user is interacting with the text-based input controls. When a user presses and releases a key, the (keyup) event occurs.


1 Answers

 $timeout(function() {
     angular.element('#myselector').trigger('click');
  }, 100);

If you want trigger on press on enter key you need to write like that

<input ng-keyup="$event.keyCode == 13 ? myFunc() : null">
like image 150
Neeraj Dubey Avatar answered Oct 21 '22 03:10

Neeraj Dubey