2016-11-18 106 views
0

我在努力;从火力数据库如何从Firebase获取图像路径,从Firebase存储获取图像并显示它?

  1. 获取图像路径
  2. 从火力存储获得的图像
  3. 显示此图像

我用Angular2/Angularfire2

这里是我当前的代码;

this.products = af.database.list('products/') 
    this.products.subscribe((data: any) => { 
     data.forEach(item => { 
      firebase.storage().ref().child('products/' + item.img) 
      .getDownloadURL() 
      .then(url => { 
       item.image = url; 
      }); 
     }) 
     } 
    ) 

这是我的模板;

<ion-card *ngFor="let item of products |async" text-center 
     [ngStyle]="item.image ? {'background': 'url(' + (item?.image) + ')'} : {}"> 

我能够获得路径,并获得下载网址。

但是我无法显示它。

任何帮助将是伟大的!

回答

0

我完成了临时解决方案,通过添加额外的数组,并显示它。任何解决方案仍然欢迎

this.productss = [] 

this.products = af.database.list('/products') 
this.products.subscribe((data: any) => { 
    data.forEach(item => { 
     firebase.storage().ref().child('products/' + item.img) 
     .getDownloadURL() 
     .then(url => { 
      item.image = url; 
      this.productss.push(item) 
     }); 
    }) 
    } 
)