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

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

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 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