PrinceG
PrinceG

Reputation: 982

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?

Upvotes: 0

Views: 48

Answers (2)

DeborahK
DeborahK

Reputation: 60528

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

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

Upvotes: 1

Evelyn Ma
Evelyn Ma

Reputation: 494

Did you try filter?

angular filter example

Upvotes: 0

Related Questions