Skip to content

Instantly share code, notes, and snippets.

@lydemann
Created November 5, 2019 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lydemann/cc42b94f9de3eabaaec5d42322add4e5 to your computer and use it in GitHub Desktop.
Save lydemann/cc42b94f9de3eabaaec5d42322add4e5 to your computer and use it in GitHub Desktop.
export class ValidationRule {
private static _validationRulesMap: Map < string, ValidationRule > ;
public static get validationRulesMap() {
if (!ValidationRule._validationRulesMap) {
ValidationRule._validationRulesMap = new Map < string, ValidationRule > ();
}
return ValidationRule._validationRulesMap;
}
public static required = new ValidationRule('REQUIRED', Validators.required);
private constructor(private name: string, public validationFn: (control: AbstractControl) => ValidationErrors | null) {
ValidationRule.validationRulesMap.set(name, this);
}
toString() {
return this.name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment