How can I display an image from Firebase storage without repeating the image in a loop

How can I display an image from Firebase storage without repeating the image in a loop? I was able to get the image data from storage, but cannot display the images as another image in this array. It just returns the same image in a loop.

Html

<div *ngFor="let list of listings"class="row">
  <img [src]="imageUrl"/>
</div>

      

JavaScript

ngOnInit() {

    this.listings = [];
    this.listingss = [];

    this.firebaseService.getListings().subscribe((data: any) => {

          data.forEach(listings => {
                this.listing = listings
                this.listings.push(listings);

                //listings logged
                console.log(listings);

                // get the reference
                let storageRef = firebase.storage().ref();
                //store the path
                let spaceRef = storageRef.child(listings.path);
                //Images logged
                // console.log('images:', listings.path);

                //download the url
                storageRef.child(listings.path).getDownloadURL().then((url) => {

                      //url is our firebase path which we store as a var imageUrl
                      this.imageUrl = url;

                      //push out the listings array of data//
                      // this.listingss.push(listings);
                      console.log(url);
                      console.log("this was a success");

      

+1


source to share


1 answer


You are overwriting this property imageUrl

every time.

You have to store this image in your array element:



listings.imageUrl = url;

      

<div *ngFor="let list of listings"class="row">
  <img [src]="list.imageUrl"/>
</div>

      

0


source







All Articles