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

263
Vistas
Angular call function inside fetch (ngOninit)

I want to call a function inside a fetch, but for some reason I get the following error and can't find a solution.

 Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'myFunction')
TypeError: Cannot read properties of undefined (reading 'myFunction')

How I should call a function inside the fetch -> then ? Minimalist reproduction at the link below:

https://plnkr.co/edit/kizI9pLOe8XZzKYz?preview

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

0

Your context is getting lost when you are declaring a function.

Use Arrow function to avoid that error as below:

fetch('https://www.ag-grid.com/example-assets/row-data.json').then( (response) => {
  return response.json();
}).then( (data) =>{
  this.myFunction(data);
})
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