In my component I have a foreach loop that is fired when a client is selected. Inside this loop I have to call a function in the same component.
To do this I must use this.functionName() to call the function. But obviously this will not work inside the foreach loop since 'this' is no longer the component itself.
Does anyone have a solution for this?
this.clientService.selectedClient.forEach(function(client) {
this.getIntake(); // not working
});
Use arrow functions
this.clientService.selectedClient.forEach((client) => {
this.getIntake(); // not working
});
otherwise this will not point to the local class instance
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With