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

266
Vistas
bind global value into ValidationErrors in angular

i try to bind value into ValidationErrors.

i have this method:

  isUniqueEmail(control: FormControl): ValidationErrors {
    if (control.value != null) {
        console.log(control.value)
        if(control.value == this.foundEmail){
          console.log("found one");
          return {isUniqueEmail: true}
        }else{
          return null;
        }
      }
  }

this method check if control.value (email typing) equal email stored in global variable this.foundEmail then we have duplicate email.

My problem is: i can retreive data from foundEmail in this method because this method is private.

this method is located inside export class exampleComponent implements OnInit.

Error: ERROR TypeError: Cannot read properties of undefined (reading 'foundEmail')

But i check i have data into foundEmail

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The validator function gets called from the FormControl so its context is not bound to the class you're defining the method on. You need to manually bind isUniqueEmail() to this.

Two options:

  1. Use bind() when defining the FormControl:

    name: new FormControl("", [
        this.isUniqueEmail.bind(this),
    ]),
    
  2. Define your validator as arrow function:

isUniqueEmail = (control: FormControl) => {
    if (control.value != null) {
        console.log(control.value)
        if(control.value == this.foundEmail){
          console.log("found one");
          return {isUniqueEmail: true}
        }else{
          return null;
        }
      }
  }
about 4 years ago · Juan Pablo Isaza 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