Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda