I have an array filled with different Image objects:
var imageList = [ image1, image2, image3 ];
Each element in this array is a variable that holds new Image()
.
For instance: var image1 = new Image()
.
I use the .onload
event to preload each image after setting its URL. Only once all images are loaded can other operations take place.
How can I display each element of the array in AngularJS and show the image?
<li ng-repeat="image in imageList">
{{ image }}
/* I want the output of the above line to appear like
<img src="./img/xx.svg" /> */
</li>
I do not want to follow a method like the one below since each element in the array has already been created as a new Image():
<li ng-repeat="image in someImageList">
<img ng-src="{{ image.url }}" />
</li>
If I try {{ image }}
, the current output shows just {}. Using solely image
results in a list containing "image" strings.
The rationale behind creating new image elements using JavaScript instead of <img/>
tags is twofold: 1. The need for preloading images, and 2. The requirement to draw these images in <canvas>
. Repeating the creation of <img/>
for the same image sources would be redundant. Additionally, it would slow down the opening of a modal displaying a collection of these images. Therefore, by preloading the images beforehand, the modal potentially opens quicker.