Open In App
Related Articles

Angular 10 (blur) Event

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

In this article, we are going to see what is blur event in Angular 10 and how to use it. The blur event is triggered when an element loses its focus.

Syntax:

<input (blur)='functionName()'/>

NgModule: Module used by blur event is:

  • CommonModule

Approach:

  • Create an Angular app to be used.
  • In app.component.ts make a function that triggers on blur event.
  • In app.component.html make an input element and set blur event.
  • Serve the angular app using ng serve to see the output.
 

Example 1:

app.component.ts

import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
  
export class AppComponent {
    onBlur(): void {
        console.log('Focus Is Lost for this Element');
    }
}

                    

app.component.html

<br>
<form>
    <input placeholder="Name" (blur) = 'onBlur()'>
</form>

                    

Output:

Example 2:

app.component.ts

import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
  
export class AppComponent {
    onBlur(): void {
        console.log('Focus Is Lost for this Element');
    }
}

                    

app.component.html

<br>
<form>
    <button  (blur) = 'onBlur()'>Click Here!!</button>
</form>

                    

Output:



Last Updated : 04 Jul, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads