I execute requests to the server and add them to the array of objects in the service:
async auth(login: string, password: string) {
let data = this.ApiService.autorization(login, password);
data = (isNullOrUndefined(await data)) ? [] : await data;
this.ApiService.cars = data['cars'];
for (let i = 0; i < this.ApiService.cars.length; i++) {
let car = this.ApiService.cars[i];
this.http.get('http://get/example/').subscribe((data) => {
this.ApiService.carsPosition.push(data[0]);
});
}
console.log(this.ApiService.carsPosition)
console.log('lenght: ' + this.ApiService.carsPosition.length)
}
The console displays the following data:
The data is received, but their length is zero. And I can’t use them. What to do?