我用的是
我想做什么,
问题
问题
组件TS
getIssueImages() {
this.albumsCollection = this.afs.collection<any>(/albums/${albumId}/images`);
this.albums = this.albumsCollection.snapshotChanges().map(actions => {
return actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
console.log(data);
// Firebase Reference
var storage = firebase.storage();
// Get the image storage reference
var image = data.image_thumbnail;
//Create an image reference to the storage location
var imagePathReference = storage.ref().child(image);
// Get the download URL and set the local variable to the result (url)
imagePathReference.getDownloadURL().then((url) => {
this.image_thumbnail = url;
});
return { id, ...data };
});
});
}
Component.HTML
<ul>
<li *ngFor="let image of images | async">
{{ image.image_thumbnail }}
</li>
</ul>
**Component.HTML -不正确**
<ul>
<li *ngFor="let image of images | async">
{{ image_thumbnail }}
</li>
</ul>
基于@James响应的更新图像更新。

发布于 2017-10-14 09:14:06
您面临的主要问题是获取下载URL的异步特性。Observable.fromPromise。
getIssueImages() {
this.albumsCollection = this.afs.collection<any>(/albums/${albumId}/images`);
this.albums = this.albumsCollection.snapshotChanges().map(actions => {
return actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
// Firebase Reference
var storage = firebase.storage();
// Get the image storage reference
var image = data.image_thumbnail;
//Create an image reference to the storage location
var imagePathReference = storage.ref().child(image);
// Get the download URL and set the local variable to the result (url)
var image_thumbnail = Observable.fromPromise(imagePathReference.getDownloadURL());
return { id, image_thumbnail, ...data };
});
});}
现在image_thumbnail是异步的。
<ul>
<li *ngFor="let image of images | async">
{{ image.image_thumbnail | async }}
</li>
</ul>https://stackoverflow.com/questions/46729931
复制相似问题