How can I check that a form has unsaved changes before closing ng-modal in Angular 5?

1.1k Views Asked by At

I have a modal popup. It has a form-group-like registration form. And it has fields like text, checkbox, select. If the user changes any form controls without saving the form, and then tries to close the modal popup, I would like to show a warning message to force saving changes or leaving the popup.

I've seen this Q&A, but I don't understand how it works. Where can I get the form-got-changed status in the FormIntactChecker class?

1

There are 1 best solutions below

0
On

you can do it like so

form = FormGroup({}); // create your FormGroup here or if you already have it, just check 
if (this.form.dirty) {}