简体   繁体   中英

What is the proper way to attach event listeners to elements inside a component template?

I have a simple SearchWidgetComponent that contains an input box. This would also display search results using li elements. I need to attach different event listeners to the input box like keydown, keyup, focus and blur. I would also need to attach mouse events on the li elements.

What is the proper way of attaching these event listeners to these elements inside a component?

Have you looked at event binding? https://angular.io/guide/user-input

                <input  id="productNameId" 
                        type="text" 
                        [(ngModel)] = product.productName
                        (keyup) = "onKeyUp()"
                        name="productName" />

Did you try filter ?

angular filter example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM