Created
April 13, 2024 15:32
define isSaving form state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected isSaveRequestInProgress = false; | |
protected get isSaveButtonDisabled() { | |
return !this.form.valid || this.isFormPristine || this.isSaveRequestInProgress; | |
} | |
protected get isResetButtonDisabled() { | |
return this.isFormPristine || this.isSaveRequestInProgress; | |
} | |
protected saveUserData() { | |
// set the saving flag | |
this.isSaveRequestInProgress = true; | |
// disable form controls | |
this.disableForm(); | |
this.saveUseData$() | |
.pipe( | |
finalize(() => { | |
// clear the saving flag | |
this.isSaveRequestInProgress = false; | |
// enable form controls | |
this.enableForm(); | |
}), | |
catchError(error => { | |
// ... | |
}) | |
) | |
.subscribe((response) => { | |
// ... | |
}) | |
} | |
private disableForm() { | |
Object.values(this.form.controls).forEach(control => { | |
control.disable() | |
}) | |
} | |
private enableForm() { | |
Object.values(this.form.controls).forEach(control => { | |
control.enable() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment