HDTuto.com

Input Keydown Event in Angular Example



Now, let's see example of angular input change event on keydown event. you'll learn keydown event in angular. if you want to see example of on keydown event in angular 9 then you are a right place. i explained simply step by step angular input keydown event example.

In this post i will show you very simple example of onkeydown event in angular. you can easily use keydown event in angular 6, angular 7, angular 8 and angular 9 application.

When user will key up on input box field then trigger onKeyDownEvent() of angular component. we will use (change) attribute for call function. let's see bellow logic code.

<input type="text" (keydown)="onKeyDownEvent($event)" />

onKeyDownEvent(event: any){

console.log(event.target.value);

}

Let's see full examples now:

Example

src/app/app.component.html

<h1>Angular Textbox Keydown Event Example - HDTuto.com</h1>

<input type="text" (keydown)="onKeyDownEvent($event)" />

src/app/app.component.ts

import { Component, VERSION } from '@angular/core';

@Component({

selector: 'my-app',

templateUrl: './app.component.html',

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

name = 'Angular ' + VERSION.major;

onKeyDownEvent(event: any){

console.log(event.target.value);

}

}

I hope it can help you...




May 15, 2020 | Category : Angular



Blog Search


Copyright © 2020 HDTuto.com. All rights reserved.