npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

form-control-change-tracker

v1.0.2

Published

[![npm version](https://img.shields.io/npm/v/form-control-change-tracker.svg)](https://www.npmjs.com/package/form-control-change-tracker) [![npm downloads](https://img.shields.io/npm/dm/form-control-change-tracker.svg)](https://www.npmjs.com/package/form-

Readme

Angular Form Control Change Tracker

npm version npm downloads License Angular CI

🚀 Live Demo

Try it on StackBlitz - Interactive demo with reactive and template-driven forms (Angular 19)

Version Compatibility

| Angular Version | Library Version | Status | | :-------------- | :-------------- | :---------------- | | v19+ | ^1.0.0 | 🟢 Stable | | v15 - v19 | 0.0.4 | 🟡 Legacy Support |

Custom Comparison Strategy

The library uses a SimpleStrategy by default, which performs a fast reference check for primitives and a key-order independent deep comparison for objects. To use a different strategy (e.g., deep-diff):

  1. Install deep-diff (or your preferred library):

    npm install deep-diff
    npm install @types/deep-diff --save-dev
  2. Create the Strategy:

    import { Injectable } from "@angular/core";
    import { ComparisonStrategy } from "form-control-change-tracker";
    import { diff } from "deep-diff";
    
    @Injectable()
    export class DeepDiffStrategy implements ComparisonStrategy {
      isEqual(a: any, b: any): boolean {
        // Returns true if no differences found
        return !diff(a, b);
      }
    }
  3. Provide it in your Module:

    import { HG_COMPARISON_STRATEGY } from "form-control-change-tracker";
    import { DeepDiffStrategy } from "./strategies/deep-diff-strategy";
    
    @NgModule({
      // ...
      providers: [
        {
          provide: HG_COMPARISON_STRATEGY,
          useClass: DeepDiffStrategy,
        },
      ],
    })
    export class AppModule {}

Very often when developers need to know if there were any changes inside the a form in order to present a unsaved changes confirmation dialog when navigating away or in order to disable the save button when there is nothing new to save. The FormControlChangeTrackerModule provides two things:

  • The ChangeTrackerDirective (hgChangeTracker) that can be set on the individual form controls in order to track if any changes are made

  • And the @hasChanges() decorator that is applied over the ChangeTrackerDirective directives in order to provide you a boolean value indicating if there are any changes or not.

Usage

1. New Container API (Recommended)

The new API allows you to track changes directly in your template without needing complex decorators.

Angular 19+ (Standalone Components)

import { Component } from "@angular/core";
import { ReactiveFormsModule, FormBuilder, FormGroup } from "@angular/forms";
import { FormControlChangeTrackerModule } from "form-control-change-tracker";

@Component({
  selector: "app-my-form",
  standalone: true,
  imports: [ReactiveFormsModule, FormControlChangeTrackerModule],
  template: `
    <form [formGroup]="form" (ngSubmit)="submit()" hgChangeTrackerContainer #tracker="hgChangeTrackerContainer">
      <div class="form-group">
        <label>First Name</label>
        <!-- Auto-captures initial value on init -->
        <input formControlName="firstName" hgChangeTracker />
      </div>

      <div class="form-group">
        <label>Last Name</label>
        <input formControlName="lastName" hgChangeTracker />
      </div>

      <!-- Check for changes anywhere in the form -->
      <button [disabled]="!tracker.hasChanges">Submit</button>

      <!-- Reset initial/default values to current values -->
      <button type="button" [disabled]="!tracker.hasChanges" (click)="tracker.resync()">Update Defaults</button>
    </form>
  `,
})
export class MyFormComponent {
  form: FormGroup;

  constructor(private fb: FormBuilder) {
    this.form = this.fb.group({
      firstName: [""],
      lastName: [""],
    });
  }

  submit() {
    console.log("Form submitted:", this.form.value);
  }
}

Legacy NgModule (Angular 15-18)

// app.module.ts
imports: [
  // ...
  FormControlChangeTrackerModule,
];

template

<form [formGroup]="form" (ngSubmit)="submit()" hgChangeTrackerContainer #tracker="hgChangeTrackerContainer">
  <div class="form-group">
    <label>First Name</label>
    <!-- Auto-captures initial value on init -->
    <input formControlName="firstName" hgChangeTracker />
  </div>

  <div class="form-group">
    <label>Last Name</label>
    <input formControlName="lastName" hgChangeTracker />
  </div>

  <!-- Check for changes anywhere in the form -->
  <button [disabled]="!tracker.hasChanges">Submit</button>

  <!-- Reset initial/default values to current values -->
  <button [disabled]="!tracker.hasChanges" (click)="tracker.resync()">Update Defaults</button>
</form>

2. Configuration Options

Debounce Time Adjust the debounce time for change detection (default: 20ms).

<input hgChangeTracker [debounceTime]="300" />

Multi-Initial Values Allow multiple values to be considered "valid" (unchanged).

<input hgChangeTracker [multiInitialValue]="true" [initialValue]="['A', 'B']" />

Auto-Sync Control whether the directive automatically captures the initial value.

<!-- Disable auto sync if you want full manual control -->
<input hgChangeTracker [autoInitialValueSync]="false" [initialValue]="startValue" />

3. Legacy Decorator API

The library serves backward compatibility for the @hasChanges() decorator usage.

@Component({...})
export class MyComponent {
  @ViewChildren(ChangeTrackerDirective) @hasChanges() hasFormChanges: boolean;
}

Features

  • Deep Comparison: Uses deep-diff strategies to correctly track object changes.
  • Reactive: Built on RxJS for efficient change detection.
  • Debounced: Prevents UI thrashing on high-frequency inputs.
  • Container Support: Easily aggregate change status for an entire form.