[英]Detect Change in Angular binding with same name but different value?
I am working with profile image change api.我正在使用个人资料图片更改 api。 Each time I change image I get changed image back from server but with the same url ( say test.jpeg ).每次我更改图像时,我都会从服务器获取更改后的图像,但具有相同的 url (比如 test.jpeg )。
url: string;
<img [src]="url" />
url : test.jpeg // url returned from server on image change first time
url : test.jpeg // url returned from server on image change second time
url : test.jpeg // url returned from server on image change third time
Though server returns different image angular is not able to detect as there is no change in url.尽管服务器返回不同的图像 angular 无法检测到,因为 url 没有变化。 How to solve this ?如何解决这个问题?
easy way to do that is adding some fake query params.简单的方法是添加一些假的查询参数。
get src() {
return this._imageSrc + '?q=' + this.hash;
}
pictureWasUpdated() {
this.hash = Math.random().toString(16)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.