Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
AsyncValidator overwrites Validator

Are there any reasons why adding a validator overwrites the existing async validator?

I use Angular 12 and addValidator() on formGroup. The docs say: "without affecting other validators."

As soon as I add the validator, async validator did not fire any more.

public testValidator(): AsyncValidatorFn {
    return (control: AbstractControl): Observable<ValidationErrors | null> => {
      return of({wrongAuthority: 123});
    }
  }

public authorityValidator(control: AbstractControl) {
   return {wrongAuthority: 12333};
}

this.form = this._fb.group({...}, { asyncValidators: this.testValidator()});

this.form.addValidators(this.authorityValidator);
this.form.updateValueAndValidity();

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Investigation of Angular code provide some results:

(this as {errors: ValidationErrors | null}).errors = this._runValidator();
(this as {status: FormControlStatus}).status = this._calculateStatus();

 if (this.status === VALID || this.status === PENDING) {
    this._runAsyncValidator(opts.emitEvent);
 }

As you can see sync validator executes first and sets the status of control then if he throws an error async validator is ignored by the value of status. That makes sense.

Github

P.S. executing of validators with console.log

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda