Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to bind concisely on multiple events in Angular 2?

Tags:

angular

events

Is there better way to bind on multiple events at once? I know I can do

<input (keyup)="callFunc()" (keydown)="callFunc()"/>..

I wonder if there is a short hand like that:

<input (keyup,keydown)="callFunc()"/>

I tried and it didn't work..

Thanks, Michael

like image 855
Michail Michailidis Avatar asked Jan 25 '16 00:01

Michail Michailidis


People also ask

Can we use two events together in Angular?

Turns out, you totally can. Run this demo in my JavaScript Demos project on GitHub. In Angular 1.

Is event binding two-way binding?

The two-way binding syntax is shorthand for a combination of property binding and event binding.

Which of the given is used for event binding in Angular?

To bind to an event you use the Angular event binding syntax. This syntax consists of a target event name within parentheses to the left of an equal sign, and a quoted template statement to the right.

What is event binding in Angular with example?

In Angular 8, event binding is used to handle the events raised by the user actions like button click, mouse movement, keystrokes, etc. When the DOM event happens at an element(e.g. click, keydown, keyup), it calls the specified method in the particular component.


1 Answers

You can implement this yourself through EventManagerPlugin.

Also there is a npm module which has this plugin already built that you can implement!!

npm install angular2-multievent-bindings-plugin --save

like image 186
Sean Larkin Avatar answered Oct 27 '22 13:10

Sean Larkin