我需要刷新像这样加载的图像:
<img [src]="linkPicture" alt="profile photo" width="150px" height="150px">
在打字稿文件中,我有一个变量 this.linkPicture,我最初存储链接。当我更新图片时不刷新。我再次设置变量….
这是我的打字稿代码的一部分
public linkPicture : string;
初始设置变量
this.service.GetProfile(id).subscribe(resp => {
.....
this.linkPicture = resp.Photo;
console.log(resp); //this show the photo
});
当我更新图片时
let dialogRef = this.dialog.open(DialogUploadPhotoComponent, {
data: {
patientID: this.ss.getCurrentUserApi().PatientID
},
width : "550px",
});
dialogRef.afterClosed().subscribe(result => {
if(result != undefined){
console.log(result);
this.linkPicture = result; //I set the new picture.
}
});
原文由 Yoedusvany Hdez 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以将时间戳查询附加到图像 URL 以强制浏览器重新加载图像。这不应该对托管图像的服务器产生任何负面影响。
更新模板以调用函数:
使用可选的时间戳值计算 URL:
更改 URL 时。创建一个新的时间戳值。
即使 URL 相同,时间戳也会发生变化,这会强制浏览器重新加载图像。