async onSubmit(formValue) {
this.isSubmitted = true;
if(this.selectedImageArray.length > 0) { // 4 images in this array
for (let index = 0; index < this.selectedImageArray.length; index++) { // Loop through this image array
await new Promise(resolve => {
setTimeout(()=> {
console.log('This is iteration ' + index);
var filePath = `images/tours/${this.selectedImageArray[index].name.split('.').slice(0,-1).join('.')}_${new Date(). getTime()}`;
const fileRef = this.storage.ref(filePath);
this.storage.upload(filePath, this.selectedImageArray[index]).snapshotChanges().pipe(
finalize(() => {
fileRef.getDownloadURL().subscribe((url) => {
formValue[`imageUrl${index+1}`] = url;
console.log(url);
});
})
).subscribe()
resolve();
}, 3000);
});
}
console.log('After loop execution');
// this.value(formValue);
}
}
После отправки кода он загрузит и распечатает 3 URL-адреса, затем напечатает «после l oop выполнения», затем напечатает 4-й, я не понимаю, почему. См. Здесь в консоли
![İmage](https://i.stack.imgur.com/8BkPf.png)
см. В строке изображения номер выполнения кода. Что я хочу, чтобы выполнить код в последовательности после загрузки всех изображений, то после того, как он будет go из l oop.