Reacting to Keyup Events with Angular

Ole Ersoy
1 min readDec 24, 2018

--

Photo by Nikhita Singhal on Unsplash

Updated Version

There is an updated version of this article here:

Scenario

We have an input field and we want to log the contents of it whenever a keyup event occurs.

Approach

First define the components keyup event handler:

keyup(event) {
console.log(event);
console.log(this.fieldvalue);
}

Note that we are logging the value both from the event that the handler receives and the fieldvalue that we bind in the component declaration.

Next declare the input field in the component template (Note that the event must start with $ as in $event ):

<input placeholder="Type stuff ..." [value]="fieldvalue" (keyup)="keyup($event.target.value)">

Brought to You By

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Ole Ersoy
Ole Ersoy

Written by Ole Ersoy

Founder of Firefly Semantics Corporation

No responses yet

Write a response