Is there a way to get notified when a form is reset via the formReset method?
I have a directive that injects the form and I can get notified when the form is submitted or reset via a reset button but I cannot figure out a way to get notified when formRest is called on ngForm.
@Directive({
selector: '[appForm]'
})
export class FormDirective implements OnDestroy {
private subscription: Subscription;
constructor(form: NgForm) {
this.subscription = form.ngSubmit.subscribe(() => {
console.log('submitted');
});
form.onReset = () => {
console.log('reset');
};
}
ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
}
}
}
Using the directive like
<form appForm #form="ngForm">
<button type="submit">Submit</button>
<button type="reset">Reset</button>
<button type="button" (click)="form.resetForm()">Angular reset</button>
</form>
Is there a way to notify my directive that the resetForm method has been called?
Demo at StackBlitz https://stackblitz.com/edit/angular-adymlf?file=src/app/form.directive.ts