I am currently working on an Angular application that retrieves data from an API and uses one of its parameters from a looped array. The issue I'm facing is that the data is pushed in a random order due to the continuous looping without waiting for the subscription to finish before pushing the result.
let parameterArray = ["a", "b", "c"]
let finalData = []
parameterArray.forEach(parameter => {
let tmpValue = /* Implement logic for parameter data transformation */
forkJoin(this.apiService.getApiData(tmpValue)).subscribe(response => {
let transformedData = /* Data processing logic */
finalData.push(transformedData);
})
})
Calling the API multiple times is not ideal, but my main goal right now is to find a way to iterate through the parameterArray and push the transformed data in the correct order. Any help would be greatly appreciated!