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

ngx-smart-forms

v1.0.0

Published

A set of utilities for managing Angular reactive forms.

Readme

🤓 ngx-smart-forms

Smart, Signal-powered form state utilities for Angular 17+

npm version Angular MIT License

ngx-smart-forms simplifies form management in Angular by adding powerful utilities like:

  • Initial value tracking
  • Dirty/changed detection via Signals
  • Reset to initial state
  • Unsaved changes guard (canDeactivate)
  • FormDebugPanelComponent for live dev inspection 🔍 - coming soon

✨ Features

✅ Track initial form values
✅ Detect changes reactively with WritableSignal<boolean>
✅ Reset whole form or selected controls
canDeactivate() helper for unsaved changes
✅ Angular 17+ & Signals-ready
✅ Dev-only debug panel component 🧪
✅ Works with standalone and traditional modules
✅ Fully tree-shakable & Ivy-compiled ✅ Support for dynamic form controls ✅ Proper memory cleanup


📦 Installation

npm install ngx-smart-forms

Angular v17 or newer required. Uses Signals.


🚀 Getting Started

1. Inject the service

import { Component, OnDestroy } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { NgxSmartFormsService } from 'ngx-smart-forms';

@Component({
  selector: 'app-my-form',
  templateUrl: './my-form.component.html',
})
export class MyFormComponent implements OnDestroy {
  form: FormGroup;

  constructor(
    private fb: FormBuilder,
    private smartForms: NgxSmartFormsService
  ) {
    this.form = this.fb.group({
      name: [''],
      email: ['']
    });

    this.smartForms.storeInitialValues(this.form);
  }
  
  ngOnDestroy(): void {
    // Prevent memory leaks
    this.smartForms.cleanupForm(this.form);
  }
}

2. Detect changes using Signals

readonly formChanged = this.smartForms.getFormChanged(this.form);
<p *ngIf="formChanged()">⚠️ You have unsaved changes.</p>

3. Reset to Initial State

this.smartForms.resetToInitialValues(this.form);

Or for selected controls:

this.smartForms.resetControlsToInitialValue(this.form, ['email']);

4. Prevent Navigation with Unsaved Changes

Use in a CanDeactivate guard:

canDeactivate(): boolean {
  return this.smartForms.canDeactivate(this.form);
}

5. Managing Dynamic Forms

When adding new controls to your form dynamically:

// Add new control
this.form.addControl('address', this.fb.control(''));

// Update initial values for new controls
this.smartForms.updateInitialValuesForNewControls(this.form);

🧠 Why Use This?

Angular gives you reactive forms, but not:

  • Initial state tracking
  • Smart "unsaved changes" detection
  • Reset logic for dynamic forms
  • Signal-powered change tracking
  • Memory leak prevention for forms

ngx-smart-forms solves all that with one clean service.


📚 API Reference

storeInitialValues(formGroup: FormGroup): void

Stores current form state as initial snapshot.


getFormChanged(formGroup: FormGroup): Signal<boolean>

Returns a reactive Signal that updates whenever the form changes.


resetToInitialValues(formGroup: FormGroup): void

Restores the full form to its original state.


resetControlsToInitialValue(formGroup: FormGroup, controls: string[]): void

Resets selected controls only.


canDeactivate(formGroup: FormGroup): boolean

Returns false if the form has unsaved changes.


updateInitialValuesForNewControls(formGroup: FormGroup): void

Updates initial values for newly added controls. Call after dynamically adding controls.


cleanupForm(formGroup: FormGroup): void

Removes all references and subscriptions for a specific form. Call in ngOnDestroy to prevent memory leaks.


🤝 Contributing

PRs, issues, and ideas welcome! Open a discussion or fork the repo and send in a pull request 💬


📝 License

MIT © 2025 [klubinskak]