Currently, I am in the process of developing a test application using Angular. The challenge arises when I attempt to retrieve data through a Get request and then return a value based on that data. The code snippet below outlines the scenario:
public getNextId(entityName: string): number {
console.info('Retrieving next ID for ' + entityName);
let seqId: SeqId;
const url = `${this.apiURL}/${entityName}`;
console.info('SeqID URL: ' + url);
this.http.get<SeqId>(url)
.subscribe((data: SeqId) => seqId = data); -> 1
/*Do something with seqId */ -> 2
return seqId.nextEntityId;
}
The issue at hand is that step (2) is executed before step (1). This results in the seqId variable not being properly set by the time step (2) is reached.
I am seeking guidance on how to effectively conduct a Get operation, process the retrieved data, and return a value within the same method. Any assistance on this matter would be greatly appreciated.
Thank you in advance.