(change) vs (ngModelChange) in Angular: What to Choose in 2024?

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Introduction: Why Does This Topic Blow Up Stack Overflow?

\n\n

If you've ever written in Angular and dealt with handling changes in <input>, you've surely seen two similar events: (change) and (ngModelChange). At first glance — they're the same. In practice — the devil is in the details. The question "(change) vs (ngModelChange) in Angular" gathers thousands of views on Stack Overflow, and for good reason: the wrong choice leads to bugs, unnecessary server requests, and sleepless nights.

\n\n

In this article on PythonLib, we will figure it out once and for all:

\n
    \n
  • How are (change) and (ngModelChange) different in Angular?
  • \n
  • When to use each one?
  • \n
  • How to avoid common pitfalls?
  • \n
\n

Let's go! 🚀

\n\n

In Short: What are (change) and (ngModelChange)?

\n\n

(change) is a standard DOM event that fires when an element loses focus (blur) and its value has changed. Angular simply wraps the native change event.

\n\n

(ngModelChange) is an event of the ngModel directive. It fires every time the model changes — literally with every keystroke (unless ngModelOptions is used).

\n\n
Important: ngModelChange cannot be used without [(ngModel)]. It is part of two-way binding.
\n\n

Here is a minimal example in TypeScript to see the difference:

\n\n
// app.component.ts\nimport { Component } from '@angular/core';\n\n@Component({\n  selector: 'app-root',\n  template: `\n    <input\n      [ngModel]="name"\n      (ngModelChange)="onNgModelChange($event)"\n      (change)="onChange($event)"\n      placeholder="Enter name">\n    <p>Value: {{ name }}</p>\n  `\n})\nexport class AppComponent {\n  name = '';\n\n  onNgModelChange(value: string) {\n    console.log('ngModelChange:', value);\n  }\n\n  onChange(event: Event) {\n    console.log('change:', (event.target as HTMLInputElement).value);\n  }\n}\n
\n\n

Try typing "Angular" — and you'll see: ngModelChange will fire 7 times (per letter), while change will fire only once, when you click outside the field.

\n\n

Key Differences: Comparison Table

\n\n

For clarity, here is a table of the key differences (change) vs (ngModelChange):

\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Criterion(change)(ngModelChange)
Event TypeNative DOM eventAngular event (EventEmitter)
When it firesOn blur + value changeOn every model change (every input)
Value in $eventEvent object (need to extract value)New model value (string, number, etc.)
Dependency on ngModelNot required (can be on any input)Requires [(ngModel)] or [ngModel]
PerformanceHigh (fires rarely)Can be frequent (on every keypress)
Usage with formsReactive forms, template-drivenTemplate-driven forms only
\n\n

When to Use (change)?

\n\n

(change) is your choice if:

\n
    \n
  • You need to react only when the field

Blogs

Book Recommendations