如何在不重复循环中的图像的情况下显示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");
答案 0 :(得分:0)
您每次都会覆盖imageUrl
属性。
您必须将该图像保存到数组元素中:
listings.imageUrl = url;
<div *ngFor="let list of listings"class="row">
<img [src]="list.imageUrl"/>
</div>