I need to make multiple calls to a service using forEach, where each call depends on the completion of the previous one. The code is as follows:
itemDefaultConfiguration.command = (onclick) => {
this.createConfiguration(configuration.components);
//wait for createConfiguration method to finish, which includes an http call with subscribe
this.initializeAllComponents(configuration.components)
};
initializeAllComponents(components: Agent[]) {
components.forEach(agent => {
this.componentService.setAgent(agent);
this.componentService.clearAnyOneOfIndex();
// wait for setAgent method to finish, which includes an http call with subscribe
})
}
Inside componentService:
setAgent(agent: Agent) {
this.agent = agent;
this.selectComponent(agent.name, undefined, "/", "/", environment.maxLevelJsonSchema);
}
The selectComponent method also includes a subscribe:
selectComponent(agentName: string, propName: string, schemaPath: string, dataPath: string, deepLevel: number) {
this.getComponentSchema(this.agentName, schemaPath, deepLevel)
.subscribe((responseSchema) => {
this.getDataFailure(propName, dataPath, responseSchema);
});
}
Can someone provide assistance? Thank you!