Currently, I am dealing with an API JSON to fetch a list of countries, followed by a list of states, and then cities within that state and country. The challenge lies in the second API call that I make. In the beginning, I load a list of continents and then proceed to retrieve the lists of countries. However, the issue arises when I have to iterate over the continents to obtain the countries. This requires me to concatenate or merge multiple lists into one, something I am struggling with. Below is the code snippet of my progress so far:
pegPaises2(): void {
let count = 0;
console.log('We are in action!');
this.httpp.get('http://www.geonames.org/childrenJSON?geonameId=6295630')
.subscribe((resContinents: Response) => {
resContinents.json().geonames.forEach(element => {
this.httpp.get(`http://www.geonames.org/childrenJSON?geonameId=${element.geonameId}`)
.subscribe((resCountries: Response) => {
resCountries.json().geonames.forEach(elementt => {
count = count + 1;
const Country = new COUNTRY;
Country.geonameId = elementt.geonameId;
Country.name = elementt.name;
console.log(count, Country);
});
});
});
});
}
I believe using an observable or an array could be advantageous. I attempted to use push but haven't come across any understandable examples (I am a beginner).