简体   繁体   English

Angular ngFor在Safari和Chrome中使用trackBy进行更改检测

[英]Angular ngFor change detection with trackBy in Safari vs Chrome

I have an application connected with firebase, it fetches the whole object whenever any change happens to it. 我有一个与firebase连接的应用程序,只要发生任何更改,它都会获取整个对象。

Lets say I have an object like this: 可以说我有一个这样的对象:

{
    count: 0,
    media: [{
      src: 'http://placehold.it/350x150'
    }, {
      src: 'http://placehold.it/350x250'
    }]
  };

whenever the count increases, I get the whole object from the backend with same src values. 每当计数增加时,我都会从后端获得具有相同src值的整个对象。 Here's what happens when the data binds with the view: 当数据与视图绑定时,将发生以下情况:

  • Chrome: The images doesn't refresh since its the same src . Chrome:由于相同的src因此图像不会刷新。 (Expected behavior) (预期行为)
  • Safari: The images reloads every time when the new object gets assigned. Safari:每次分配新对象时,图像都会重新加载。

I've also tried using trackBy: media?.src but getting the same result. 我也尝试使用trackBy: media?.src但得到的结果相同。

Is this an issue with Angular's trackBy or is it just how Safari works??? 这是Angular的trackBy还是Safari的工作原理???

Check this plunker . 检查这个矮子

The problem here is that trackBy: Object?.property is deprecated and using a tracking function trackBy: trackByFn works like a charm. 这里的问题是,不赞成使用trackBy: Object?.property ,并且使用跟踪功能trackBy: trackByFn就像一个trackBy: trackByFn一样工作。

Though I think Chrome handles DOM changes more gracefully than Safari. 尽管我认为Chrome可以比Safari更优雅地处理DOM更改。

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

相关问题 Angular ngFor trackBy 不工​​作。 不更新 DOM - Angular ngFor trackBy not working. Not Updating DOM 即使使用 trackBy,Angular 2 也会在 ngFor 中重建 DOM - Angular 2 rebuilds DOM in ngFor even when trackBy used Angular OnPush 更改检测传播到 ngFor 循环中的子组件 - Angular OnPush Change Detection Propagation to a Child Components in a ngFor Loop Angular 2输入绑定vs字符串更改检测 - Angular 2 Input binding vs string change detection 如何避免使用TrackBy函数避免为nGFor重建DOM-Angular Firestore - How to avoid Avoid Rebuilding DOM for nGFor using trackBy function - Angular Firestore 我在 angular 项目中有多个 ngFor 使用 trackBy:trackByFunction 与单个 function 或创建多个 function? - I have multiple ngFor in angular project use trackBy:trackByFunction with single function or create multiple function? Chrome / Safari和Firefox中的Angular Http Get返回不同 - Angular Http Get return different in Chrome/Safari vs Firefox Angular trackBy 不更新 dom - Angular trackBy not updating dom 在Chrome和Safari浏览器中检测自定义协议的方法 - Approaches of detection of custom protocol in chrome and Safari browsers 更改Angular 2中流的检测? - Change detection for stream in Angular 2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM