【发布时间】: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