1

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

1 Answer 1

3

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);
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.