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
Turns out, you totally can. Run this demo in my JavaScript Demos project on GitHub. In Angular 1.
The two-way binding syntax is shorthand for a combination of property binding and event binding.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With