Probably a naive question but I wanted to understand, and that's why posting the question.
I have to make three different API calls and store some values in an array. I am using this to achieve that:
getNodeDetails() {
this.httpClient
.get<string[]>(this.nodeURL)
.subscribe(res => {
this.nodeCount = Object.keys(res).length;
Object.values(res).forEach(value => {
this.nodeArray.push(value);
});
this.getTotalTransactions();
});
}
getTotalTransactions(): void {
this.httpClient
.get(this.transactionURL)
.subscribe((data) => {
this.numberOfTransactions = data.length;
data.forEach(apiData => {
this.totalUniqueTransactionId.push(apiData.uniqueTransactionId);
this.dateArray.push(apiData.requestTime);
});
this.totalUniqueTransactionId.forEach(transactionId =>
this.column1.push(transactionId.substr(0, transactionId.indexOf('-'))));
});
let newData: any = [];
this.nodeArray.forEach(node => {
this.httpClient.get(this.URL1 + node).subscribe(data => {
console.log(data);
this.dynamicColumns.push(data);
});
});
this.getDataMapping();
}
Now the problem that I am facing is that these calls need to be in such a way that I need all the data before I render the table. I am getting the response, but I want to make it in such a way that I need to obtain the results for the API before calling the getDataMapping()
function.
Can anyone advise me for the same?
EDIT : since the API is called in the loop, arrays needed to be received before processing the furthur logic. This is what I couldn't find while searching over.
Thanks