Introduction
In this article we will see events handling in Angular. In this article we will cover all types of events like input events , button events, form events, mouse events, checkbox events , radio button events etc. I hope you will find this article helpful.
In this article we will cover,
- Button Events
- Mouse Events
- Input Events
- Checkbox Events
- Radio Button Events
- Form Event
Create new project
For creating a new Angular project open Visual Studio code or you can use any IDE as per your choice then open folder where you want to save your project and open terminal from terminal menu or you can use short cut key ctrl+shift+~ .
Now enter thebelow command in your terminal. Here EventsInAngular is my project name
- ng new EventsInAngular
Now Angular cli asks you some questions for adding something in this project which are.
First one is for users in your app
Do you want to enforce a more strict type checking and bundle budgets in the workspace?
This setting helps improve maintainability and catch bugs ahead of time.
For more information, see https://angular.io/strict (y/N)
Enabling this flag initializes your new workspace or application with a few new settings that improve maintainability, and helps you catch bugs ahead of time. Additionally, applications that use these stricter settings are easier to statically analyze, which can help the ng update command refactor code more safely and precisely when you are updating to future versions of Angular.
If you want to add this press Y or for not adding press N.
Second one is routing
If you want to add routing in project then enter Y otherwise N. In this project as of now we does not need routing so I press n.
Third one is style sheet format
Here you need to choose your style sheet from css, scss , sass , less , stylus . Choose as per your need.

Now installnAngular cli install node module.

In this project we are using Angular 11.

Events In Angular
Here I create a function in ts file which takes one parameter event name and then console event name. We will call this function on different events.
- import { Component } from '@angular/core';
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.sass']
- })
- export class AppComponent {
- title = 'EventsInAngular';
- eventCallFunction(eventName){
- console.log(eventName +" is called ...")
- }
- }
Button Events
- Click Event
- Double Click Event
Button Click Event
ing
As we learn in JavaScript or JQuery click event is fired when user clicks on button. This event is used when we want to call something when button is clicked. For define click event in angular we need to define it as (click)=”yourfunction()”.
Button Double Click Event
This event fires when user double clicks on button. This event is used when we want to take any action or show user something when they double click on any button. For defining double click event in angular we need to define it as (dblclick)=”yourfunction()”.
- <h2 style="color: green;">Button Events</h2>
- <button (click)="eventCallFunction('Button Click ')">Button Click Event</button>
- <br><br>
- <button (dblclick)="eventCallFunction('Button Double Click ')">Button Double Click Event</button>
Mouse Events
- Mouse enter event
- Mouse leave event
- Mouse down event
- Mouse up event
Mouse Enter Event
This event fires user’s mouse enter on any element. We can call this event on any element. For defining a mouse enter event in Angular we need to define it as (mouseenter)=”yourfunction()”
Mouse Leave Event
This event fires user’s mouse leave event from any element. We can call this event on any element. For defining mouse leave event in angular we need to define it as (mouseleave)=”yourfunction()”
Mouse Down Event
This event fires user’s mouse press on any element. We can call this event on any element. For defining mouse down event in angular we need to define it as (mousedown)=”yourfunction()”
Mouse Up Event
This event fires user’s click on any element and after that when mouse button goes up. We can call this event on any element. For defining mouse up event in Angular we need to define its as (mouseup)=”yourfunction()”
- <h2 style="color: green;">Mouse Events</h2>
- <button (mouseenter)="eventCallFunction('Mouse Enter ')">Mouse Enter Event</button>
- <br><br>
- <button (mouseleave)="eventCallFunction('Mouse Leave')">Mouse Leave Event</button>
- <br><br>
- <button (mouseup)="eventCallFunction('Mouse UP')">Mouse Up Event</button>
- <br><br>
- <button (mousedown)="eventCallFunction('Mouse Down')">Mouse Down Event</button>
Input Events
- Key Down Event
- Key up Event
- Key Press Event
- Cut Event
- Copy Event
- Paste Event
- Focus Event
- Blur Event
- Input Event
- Select Event

Hamid KhanPosted Mar 8, 2021, 2:35 PM
Good collection.. Nice article