Smart, Signal-powered form state utilities for Angular 17+
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
✅ 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
npm install ngx-smart-forms
Angular v17 or newer required. Uses Signals.
import { Component } 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 {
form: FormGroup;
constructor(
private fb: FormBuilder,
private smartForms: NgxSmartFormsService
) {
this.form = this.fb.group({
name: [''],
email: ['']
});
this.smartForms.storeInitialValues(this.form);
}
}
readonly formChanged = this.smartForms.getFormChanged(this.form);
<p *ngIf="formChanged()">⚠️ You have unsaved changes.</p>
this.smartForms.resetToInitialValues(this.form);
Or for selected controls:
this.smartForms.resetControlsToInitialValue(this.form, ['email']);
Use in a CanDeactivate
guard:
canDeactivate(): boolean {
return this.smartForms.canDeactivate(this.form);
}
Angular gives you reactive forms, but not:
- Initial state tracking
- Smart "unsaved changes" detection
- Reset logic for dynamic forms
- Signal-powered change tracking
ngx-smart-forms solves all that with one clean service.
Stores current form state as initial snapshot.
Returns a reactive Signal that updates whenever the form changes.
Restores the full form to its original state.
Resets selected controls only.
Returns false
if the form has unsaved changes.
PRs, issues, and ideas welcome! Open a discussion or fork the repo and send in a pull request 💬
MIT © 2025 [klubinskak]