Angular 2 Keyup Event Textbox – Examples

Angular 2 Keyup Event Textbox Examples

Angular 2 Keyup Event Textbox – Examples
1.      The KeyUp event is triggered when the user releases a Key.
2.      The KeyDown event is triggered when the user presses a Key.
3.      The KeyPress event is triggered when the user presses & releases a Key.


The examples for KeyUp event,

Syntax:- 

<input type="text" [(value)]="values" (keyup)="onKeyUp($event)" />

HTML Component-

<div class="ibox-title">
    keyup Event - <input type="text" [(value)]="values" (keyup)="onKeyUp($event)" />
    <span><strong class="txt-color">Resut-</strong>{{values}}</span>
</div>

Home Component -

import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';

@Component({
    selector: 'home',
    templateUrl: './home.component.html',
    styleUrls: ['./home.component.css'],
})

export class HomeComponent {
    userlist: Users[];

    constructor() {
        this.userlist = [{ Id: '1001', name: 'Anil Singh', site: 'http://www.code-sample.com' },
        { Id: '1002', name: 'Alok', site: 'http://www.code-view.com' },
        { Id: '1003', name: 'Reena', site: 'http://www.code-sample.xyz' },
        { Id: '1004', name: 'Dilip', site: 'http://www.codefari.com' },
        ];
    }

    values = '';
    onKeyUp(event: any) {
        this.values = event.target.value;
        console.log(this.values);
    };
}

export class Users {
    Id: String;
    name: String;
    site: String;
}

I hope you are enjoying with this post! Please share with you friends. Thank you!!
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.