The below code returns an empty array, and I'm having trouble understanding why. What is the standard practice for pushing objects to an array from a return Observable?
In jobServices.ts:
getCities(city){
return this.http.get(`http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=70d86e78cabf44f710fd89936c709750`)
}
In Home.ts
cities = ["Atlanta", "Chicago", "New York", "Los Angeles", "San
Diego", "Athens", "Miami", "Nashville", "Austin", "Amsterdam",
"Paris" ]
citiesPayload = []
constructor(public jobService: JobService) { }
ngOnInit() {
this.returnCities();
}
returnCities(){
for (var i = 0; i < this.cities.length; i++){
this.jobService.getCities(this.cities[i])
.subscribe(city => {
this.citiesPayload.push(city);
});
}
console.log(this.citiesPayload)
}