Open In App
Related Articles

What is the difference between change and ngModelChange in Angular?

Improve Article
Save Article
Like Article

The change event is fired for <input>, <select>, and <textarea> elements when an alteration to the element’s value is committed by the user.The change event is not necessarily fired for each alteration to an element’s value. change is a DOM event that is it can trigger changes in HTML tags and elements. 

  • Syntax:
    <input  (change)="function($e)">
  • Example: 
    HTML file:

<label>Choose your favorite cartoon:
  <select class="cartoon" name="cartoon">
    <option value="">Select One …</option>
    <option value="Tom and Jerry">Tom and Jerry</option>
    <option value="Doraemon">Doraemon</option>
    <option value="Phineas and Ferb">Phineas and Ferb</option>
<div class="result"></div>

Typescript file: 

const selectElement = document.querySelector('.cartoon');
selectElement.addEventListener('change', (event) => {
  const result = document.querySelector('.result');
  result.textContent = `You like ${}`;

  • Output

When the user wants to change the model, by entering text into the input, the event callback fires and sets the new value to the model. We can’t use mgModelChange without ngModel because the ngModel class has update function with EventEmitter instance. ngModelChange will only be fired when the model will change or update.

  • Syntax 
<input [(ngModel)]="value" (ngModelChange)="function($e)">
  • Example 
    HTML file: 

<div style="color: red" *ngIf="isInvalid">
          Please check your ranges
<form (submit)="onSubmit()"
    <h3>Price Filters</h3>
    <span>Greater than:</span>
    <input type="number" name="greaterThanValue" 
    <span>Less than:</span>
    <input type="number" name="lessThanValue" 
    <input type="submit">

  • Typescript file: 

import { Component } from '@angular/core';
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
export class AppComponent  {
  public greaterThanValue = 0;
  public lessThanValue = 1;
  public isInvalid: boolean = false;
  public onChange(event: any): void {
    this.isInvalid =
     this.greaterThanValue > this.lessThanValue;

  • Output 


change ngModelChange
change is bound to the HTML onchange event. It is a DOM event. ngModelChange is bound to the model variable binded to your input.
No such class is required. ngModelChange need ngModel class to function.
change event bound to classical input change event. ngModelChange It fires when the model changes. You cannot use this event without ngModel directive.
change triggers when the user changes the input. ngModelChange triggers when the model changes, irrespective of that change is caused by the user or not.


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 16 Dec, 2020
Like Article
Save Article
Similar Reads
Complete Tutorials