I'm trying to implement a test application with Angular. The issue scenario is that I need to do a Get and return a value based on the data gotten from that Get request. See below:
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 thing is that (2) executes before (1). When (2) is reached seqId variable hasn't been set yet.
How can I do a Get, process the data retrieved and return something, all in the same method?
Thanks in advance