Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind a custom directive to all input elements?

I have a custom directive called HandleScroll and I need to add this directive to all input elements. When I initially built it , it was only needed on one input elements so I added it manually as:

< Input handle-scroll....

But now I realize that I need to add this directive to each and every input element. Is there an easy way to do this using Javascript or will I have to sit and manually add this directive to each input tag ?

Update----Thank you everyone for your help, due to some updates I no longer need to use the directive , but need to bind an event listener to each input field. I've posted the new question at: Adding an event listener to each input field , if you can help please do , I greatly appreciate it !

like image 636
Arik Badami Avatar asked Oct 29 '25 13:10

Arik Badami


1 Answers

In your directive class, you can set the selector in your decorator :

@Directive({
    selector: 'input'
})
export class HandleScroll...
like image 62
Bernard Pagoaga Avatar answered Nov 01 '25 03:11

Bernard Pagoaga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!