I have a form that displays a list of elements. They all share a common save button which is disabled until the form becomes dirty. Then
When using Angular's reactive forms, you can use markAsPristine() on the FormGroup:
export class MyPage
// Your form group
public formGroup: FormGroup;
ngOnInit() {
this.formGroup = this.formBuilder.group({
// Add your form controls here
});
}
onSubmitForm() {
// Get form value and save data on the server
// ...
this.formGroup.markAsPristine(); // <=== Mark form group as pristine
}
}
See also: documentation for AbstractControl.markAsPristine(). Note: FormGroup is a subclass of AbstractControl. It will mark all children of the FormGroup as pristine.