【问题标题】:How can I display an image from Firebase Storage without repeating image in the loop如何显示来自 Firebase 存储的图像而不在循环中重复图像
【发布时间】:2017-08-03 15:14:48
【问题描述】:

如何在不重复循环的情况下显示 Firebase 存储中的图像?我成功地从存储中获取图像数据,但无法在该数组中将图像显示为不同的图像。它只是在循环中返回相同的图像。

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");

【问题讨论】:

    标签: javascript angular firebase firebase-storage


    【解决方案1】:

    您每次都在覆盖 imageUrl 属性。

    您必须将该图像保存到您的数组元素中:

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

    【讨论】:

      猜你喜欢
      • 2021-06-06
      • 2018-08-13
      • 2021-06-11
      • 2020-11-06
      • 2016-09-28
      • 2022-01-04
      • 2021-02-18
      • 2017-12-01
      • 2022-01-19
      相关资源
      最近更新 更多