Back

InputkeyEvent

Introduction

I always forget how can i listen input event. So I write this post.

Listening Event

With out Angular

With out Angular framework we have to use javascript to bind event like this code

<input type="text" id="myInput">
document.getElementById('myInput').addEventListener('keyup', myInput);

function myInput(input) {
  console.log(input.keyCode);
}

EventList

KeyCodeRef

SourceCode

With Angular

With Angular framework is more easier to bind event

<input type="text" (keyup.enter)="onEnter()">
  onEnter(): void {
    console.log("submit");
  }

SourceCode

you can change another key like shift or anthoer you want