response screenshot image I receive an array of values from JavaScript promise. When I console.log, I can print it's value. But cannot print its array.length. please see te comments in getImageUrl() method
public saveImages() {
for (let img of this.multipleImages) {
if (img.file) {
this.promise = this.FileUploadService.
addFile(img.file, img.randomName);
this.promise.then(result => {
this.setImageUrl(result);
});
}
}
}
setImageUrl(result) {
this.imageUrl.push(result);
}
getImageUrl() {
console.log(this.imageUrl.length, // length is always 0
this.imageUrl[0], //undefined
this.imageUrl); // has value (result from promise)
}
ngOninit() {
this.saveImages();//saves the image and calls the setImageUrl method.
this.getImageUrl();
}
when this.getImageUrl() is called, you can see what is print and what is not in the console.log of getImageUrl() method.