繁体   English   中英

检测名称相同但值不同的 Angular 绑定变化?

[英]Detect Change in Angular binding with same name but different value?

我正在使用个人资料图片更改 api。 每次我更改图像时,我都会从服务器获取更改后的图像,但具有相同的 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

尽管服务器返回不同的图像 angular 无法检测到,因为 url 没有变化。 如何解决这个问题?

简单的方法是添加一些假的查询参数。

 get src() {
   return this._imageSrc + '?q=' + this.hash;
 }

 pictureWasUpdated() {
  this.hash = Math.random().toString(16)
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM