In my Angular Projekt I have this Code:
ngOnInit() {
var countTo = 50;
for (let i = 1; i < (countTo + 1); i++) {
this.http.get('https://projekt-dunkelbunt.de/index.php/wp-json/wp/v2/media?max_page=25&page=' + i).subscribe(data =>{
for(let key in data){
if(data.hasOwnProperty(key)){
this.media.push(data[key]);
console.log(this.media);
this.descriptions.push(data[key].description.rendered.split('>', 7));
console.log(this.descriptions);
}
}
console.log("AFTER FOR Length: " + this.media.length);
if (this.media.length != (this.counter * 10)) {
this.execute = false;
}
this.counter++;
}, error => {
console.error("Fehler beim Laden: " + i + " - " + error);
i = countTo + 1;
this.loadPictures();
});
}
inializeDefaultButtons();
console.log("ngOnInit(bilder.component.ts) -> done!");
}
My Problem with this Code is, that the for gets executed AFTER the inializeDefaultButtons() and I dont know why, I need the Data from the FOR in the inializeDefaultButtons() Method, but right know the inializeDefaultButtons() Method gets executed and after that the for gets executed.
What am I doing wrong?