I am trying to populate an array in my component called processes
which is an array of process
. Each process
also has a list of tasks
.
So currently, I am working with two api calls which are:
/processes
and
/process/{processId}/tasks
I use /processes
to get all the processes and initially populate the processes
array. Then I use the process id of each process
to call the second API to get the tasks of that process.
Currently, my code looks something like this:
this.processes.forEach((process, index) => {
myService.getTasks().subscribe((tasks) => {
process.tasks = tasks;
})
})
I understand that I can create an array of observables, and use Observable.forkJoin()
to wait for all these async calls to finish but I want to be able to define the subscribe callback function for each of the calls since I need a reference to the process
. Any ideas on how I can go about approaching this issue?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…