I am stuck in a situation where I am using toPromise()
with async method to get the http data in my angular app . I have to use the first promise data to be passed to second promise as an input to get the data again .
But the execution in not happening in the flow I want.
My TS -
IdSelection() : number[]{
var Ids : any[]=[];
this.selection.selected.forEach(element => {
Ids.push(element.Id);
});
var commIds : number[]=[];
Ids.forEach(async element => {
const res = await this.TaskService.getCmntDetails(element , 0 , '%27%27').toPromise();
if(res["commentId"] !=null){
res["commentId"].forEach(async data => {
const innerRes = await this.TaskService.getCmntDetails(0, Number(data) , '%27%27').toPromise();
innerRes["commentNewId"].forEach(ele => {
commIds.push(ele);
});
});
}
});
return commIds;
}
When I call this method, I am getting the value in res
variable , but soon after that the execution is going to the return statement , and it returns null .
When I debugged and checked after it returns null , the execution comes back to the second promise and the thing is executed .
Can anyone help me out on how to make 2 observables / 2 http calls at a time where the first observable output is used as the input for 2nd ?
TIA