I'm feeling pretty lost when it comes to handling promises. I've been doing a lot of reading, particularly in the context of Typescript and Angular, as I'm working on fetching data from an API REST. Within my code, there's a method called getServices which retrieves information from the API and returns an array.
The issue arises when I try to call this method:
this.getServices = (query) => {
return this.source.getServices(query)
.then(this.transformToSegments(false));
};
Upon doing so, I encounter a TypeError: results is undefined.
It seems that the problem lies with transformToSegments, where it's attempting to work on an undefined result. After extensively using console.log() for debugging, I've realized that transformToSegments executes before getServices is resolved. Clearly, something is off here, but despite my best efforts, I haven't been able to rectify it.
If anyone could lend some guidance, I would greatly appreciate it!
Many thanks,
Julia