【发布时间】:2018-12-12 17:11:11
【问题描述】:
所以我像这样从 HTTP GET 显示我的图像
<div *ngFor="let item of (currentGallery$ | async)?.imagesID" class="col-4">
<img class="img-fluid" src="url/{{item}}/thumb">
</div>
但是在将图像上传到服务器并在画廊中显示新图像之后会出现问题。
到目前为止,我唯一的解决方案是在上传 POST 后,触发新的 GET 请求,但这似乎很糟糕。
this.http.post(url, formImageData).subscribe(data => {
this.currentGallery$ = this.http.get<GalleryData>('url');
}
我的帖子返回上传的imageID,我用它来显示图像,那么在成功发布请求后如何将它放入我的observable currentGallery$ 中的数组'imagesID' >,所以 ngFor 可以在 POST 之后无需第二次 GET 就可以更新自己?
或者也许还有其他更合适的方法?
【问题讨论】:
标签: angular post httpclient ngfor angular7