I have a service that returns an Observable containing a collection of objects. The initial web call returns a collection, however within the collection of items, I need to make a supplementary call to retrieve some extra data. The result should be a new object which is generated using the two responses.
The code looks a bit like this:
let result: Array<InvitationModel> = new Array<InvitationModel>();
this.apiService.getInvitations().map((invitations : Array<InvitationResponse>) => {
invitations.forEach(inv => {
this.apiService.getInvitationData(inv).map((data: DataResponse) => {
result.push(new InvitationModel(inv, data));
});
});
return result;
This doesn't work, which I understand, but I'm not sure of the correct way to write it so that I can only return result once the loop has completed.
Any advice would be appreciated.