A Straightforward Example:
const tasks = [];
for (let i = 0; i < this.initialData.length; i++) {
tasks.push( this.taskService.getDetails(this.id1[i], this.id2[i])
};
combineLatest(...tasks).subscribe(taskGroup => {
console.log(taskGroup.id);
});
the output is 1 2 3 4 5
A More Complex Example and a Challenge:
private handleTask(foot) {
const tasks = [];
for (let i = 0; i < this.initialData.length; i++) {
tasks.push( this.taskService.getDetails(this.id1[i], this.id2[i])
};
combineLatest(...tasks).subscribe(taskGroup => {
console.log(taskGroup);
// How can I update foot.param with all taskGroup ids?
});
return this.taskService.getFoot(foot);
}
the function executes this:
return this.taskService.getFoot(foot);
before this:
console.log(taskGroup);
Is there a way to ensure that the function waits for the completion of the subscription, and then update foot.param with all taskGroup ids before returning?