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

171
Vistas
Angular arrow function, "this" is undefined

I am using Angular and call another function that makes an api call to check something. When I call the function, the this inside it is undefined!? why would this be? and how do I fix it? is my arrow function call incorrect?

This is the function that is calling the arrowFunc

onProductChanged(event) {
  this.arrowFunc(hasRangeConfigurations => {
    console.log("do something");
  })
}

This the the function that the above calls, the "this" is undefined in the const declaration at this point, but in the above it is a reference to my angular component.

arrowFunc(action: (hasRangeConfigurations: boolean) => void) {
    const criteria = {
        brandId: this.marketingRange?.brand?.id,
        pageNumber: 1,
        pageSize: 1,
    } as Myresults
    
    // extra code here
});

Interestingly this does exist outside the const but inside the const it is undefined!?

-- UPDATE My Solution--

Well before you know it someone deletes your question and forwards you to something else that is confusing.

As I cant ask a legitimate question as it gets deleted, I solved it this way, just assigning this to self (like I had done back in the jquery/javascript days) I dont know if this is the best solution, but hey hoo!

arrowFunc(action: (hasRangeConfigurations: boolean) => void) {
        const self = this;
        const criteria = {
            brandId: self.marketingRange?.brand?.id,
            pageNumber: 1,
            pageSize: 1,
        } as Myresults
        
        // extra code here
    });
about 4 years ago · Juan Pablo Isaza
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