简体   繁体   English

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

[英]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.

相关问题 如何在Angular中检测具有相同值@Input()的变化? - How to detect change with same value @Input() in Angular? 角度-检测 <input /> 通过单向绑定改变价值 - Angular - Detect <input /> value change with one way binding 如何根据不同条件在角度2中更改相同按钮的值 - How to change the value of same button in angular 2 based on different conditions 如何在Angular中用不同的变量连接绑定值? - How to concat binding value with different variables in Angular? 检测孩子内部的 Input() 值变化(角度) - Detect Input() Value Change Inside Child (Angular) 编剧 - 如果我有多个同名下拉菜单,如何使用定位器访问 Angular 2 向绑定 model 值? - Playwright - how do I access an Angular 2-way binding model value with locator if I have multiple dropdowns of the same name? Angular2 2 路绑定中同名的自定义输入和输出 - Custom input and output on same name in Angular2 2 way binding 角度绑定列表到另一个具有不同属性名称的列表 - Angular binding list to another list with different property name 角@Input,将对象绑定到同一对象但具有不同的属性名称 - Angular @Input, binding object to same object but with different property names Angular 2将同一单击事件绑定到多个元素并更改类 - Angular 2 Binding same click event to multiple elements and change class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM