Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
Angular KeyUp Event on Input Example

Angular KeyUp Event on Input Example

Aman Jain, September 22, 2022November 8, 2023

Angular KeyUp Event on Input is an Angular event binding it triggers when user interacts with DOM like text based input element and when we key up the input. Input events in angular can be handled using input and output decorators and in this tutorial we will learn Angular KeyUp Event on Input with Example. In core javascript we use onkeyup event to handle the keyup events of input but in angular it there is different way to handle the input events like for key press event we use @output decorator to input element and to handle the event of key up we use (keyup) attribute.

Angular is most popular frontend framework and it has its on guidelines to handle events, forms, rendering etc. In this example we will implement a Simple keyup Event and then we will handle it in typescript component file.

this example of (keyup) in angular will work in all angular version including angular 2, angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13 and angular 14 application.

Simplest way to use keyup is as follow

<input (keyup)="keyup($event)" 
    type="text" 
    placeholder="Enter new PIN" 
/> 
keyPress(event: KeyboardEvent) {
  let  keycode = String.fromCharCode(event.charCode);
  console.log("values",event.target.value,keycode);
}

Here we simply assigned the (keyup) to input element and then handled the event in component as above.

Let’s take an example of it

Step 1 : Create an angular app

First step is to setup an angular app using below command

ng new example-app

Step 2: Create a Component

Create a component and a method

ng g c hello-world
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-hello-world',
  templateUrl: './hello-world.component.html',
  styleUrls: ['./hello-world.component.css'],
})
export class HelloWorldComponent implements OnInit {
  
  constructor() {
  }
  keyup(event: any) {
    let  keycode = String.fromCharCode(event.charCode);
    console.log("values",event.target.value,keycode);
  }
  ngOnInit() {}
}

Here we used to keyup method to handle the input

Step 3 : Create template and add html

Now, add simple html template with input field

<h2>Angular keyup Event on Input Example</h2>

<input (keyup)="keyPress($event)" 
    type="text" 
    placeholder="Enter new PIN" 
/> 

Share this:

  • Facebook
  • X

Related

Javascript Angular angulareventkeyup

Post navigation

Previous post
Next post

Related Posts

Javascript Laravel Ajax Autocomplete Using Select2

Laravel Ajax Autocomplete Using Select2

July 17, 2022July 17, 2022

In this article we will learn to use Laravel Ajax Autocomplete Using Select2. Select2 is useful when we want live search of bulk data or to convert the existing select boz with multi features like search, multi select and options customizations. Autocomplete search is mostly work of javascript and when…

Share this:

  • Facebook
  • X
Read More
Javascript How to create global variable in angular ?

How to create global variables in angular ?

October 3, 2022November 8, 2023

In this article, we will learn about the create global variables in Angular and how to use them. We will also see how to use them across the application by importing the file. There are different ways to create global variables in angular. One way is to use the global…

Share this:

  • Facebook
  • X
Read More
Javascript Set focus on input angular example

Set focus on input angular example

September 25, 2022November 8, 2023

Angular is a great framework for building front-end web applications. One of its many features is the ability to set focus on input angular element. This can be useful in a variety of situations, such as when you want to focus on a particular input field after a user clicks…

Share this:

  • Facebook
  • X
Read More

Leave a ReplyCancel reply

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • How to Call Controller Method from Another Controller in Laravel ?
  • How to Get Domain Name in Laravel ?
  • How to Append Query String to Route in Laravel ?
  • How to Append URL Query Params to Pagination Laravel ?
  • How to Get Today Records in Laravel ?
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version