Can anyone help me with executing a For loop synchronously in Angular 5? The code I have so far doesn't wait until ExcecuteAsyncCode is completed.
let items = new Array<Item>();
for (let i = 0; i <= 10000; i += 1) {
this.ExcecuteAsyncCode(i).then(
res => {
let result = res;
return result;
}).then(response => {
let temp = response as Item[];
temp.forEach((cta: Item) => {
items.push(cta);
});
});
// THIS EXCECUTED BEFORE ExcecuteAsyncCode PROMISE COMPLETED
if (items.length < i) {
return;
}
}