Skip to content

Instantly share code, notes, and snippets.

Last active October 18, 2023 19:54
  • Star 17 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Get all validation errors for Angular FormGroup
import { FormGroup, ValidationErrors } from '@angular/forms';
export function getFormValidationErrors(form: FormGroup) {
const result = [];
Object.keys(form.controls).forEach(key => {
const controlErrors: ValidationErrors = form.get(key).errors;
if (controlErrors) {
Object.keys(controlErrors).forEach(keyError => {
'control': key,
'error': keyError,
'value': controlErrors[keyError]
return result;
Copy link

You might want to remove that space after the key "control " (drove me crazy)

Copy link

wow! that's evil! 😄


Copy link

domagoj03 commented Oct 14, 2019

Thanks. I needed support for nested forms so I forked your gist.
It can even be modified to namespace errors depending on form but right now this seems sufficient.

Copy link

WildChildForLife commented Feb 14, 2022

Useful, thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment