Skip to content

Instantly share code, notes, and snippets.

@guiseek
Created October 23, 2019 23:14
Show Gist options
  • Save guiseek/a430dd3dbb174cf51738fa3b33d9c441 to your computer and use it in GitHub Desktop.
Save guiseek/a430dd3dbb174cf51738fa3b33d9c441 to your computer and use it in GitHub Desktop.
import { FormErrors } from '../interfaces/form-errors.interface';
export const FORM_ERRORS_CONFIG: FormErrors = {
required: error => `Este campo é obrigatório`,
email: error => `Email inválido`,
min: ({ min, actual }) => `O mínimo é ${min} e tem ${actual}`,
max: ({ max, actual }) => `O máximo é ${max} e tem ${actual}`,
minlength: ({ requiredLength, actualLength }) =>
`O mínimo é ${requiredLength} e tem ${actualLength}`,
maxlength: ({ requiredLength, actualLength }) =>
`O máximo é ${requiredLength} e tem ${actualLength}`,
pattern: ({ requiredPattern, actualValue }) =>
`Esperado ${requiredPattern} e tem ${actualValue}`,
};
import { InjectionToken } from '@angular/core';
import { FORM_ERRORS_CONFIG } from './form-errors.config';
export const FORM_ERRORS_CONFIG_TOKEN = 'FormErrors';
export const FORM_ERRORS = new InjectionToken(FORM_ERRORS_CONFIG_TOKEN, {
providedIn: 'root',
factory: () => FORM_ERRORS_CONFIG
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment