I have an angular application that uses a service to populate an array to use in a table, but the results need a second transformation before they are ready for presentation. I'm calling another service to do so, but how so I know when I am completely finished with all transformations before I alert the UI that I'm finished? I tried this (naive approach) but it has a flaw:
this.dataService.getData().subscribe(result => {
result['entries'].forEach(entry => {
let fieldToTransform = entry['fieldToTransform'];
this.transformService.transform(fieldToTransform).subscribe(transformedField => {
entry['fieldToTransform'] = transformedField;
});// hmm, can't alert UI here
});// not here either
});
But it's pretty clear that each iteration of the loop will call the service and will finish at different times. How can I know when they are all done?