Ang-ng重复引起闪烁 [英] Angular ng-repeat causes flickering
本文介绍了Ang-ng重复引起闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用这段代码显示缩略图列表:
I'm displaying a list of thumbnails with this code:
<div class ="channel" ng-repeat ="channel in UIModel.channels" ng-class ="{evenchannel: ($index % 2) == 0, oddchannel: ($index % 2) == 1}">
<img class="channel-img" ng-src ="data/channels/{{$index + 1}}/thumb"/>
</div>
在控制器中,我有一个抓取新缩略图的ajax请求。 Angular因此更新图像,但会导致闪烁。有没有办法在更新DOM的过程中将缓冲区加倍或者没有删除列表?
In the controller I have an ajax request which grabs new thumbnail images. Angular thus updates the images but causes flickering. Is there a way to double buffer or not have the list deleted in the process of updating the DOM?
推荐答案
@ cexbrayat的答案,如果你没有任何ID,你也可以把它关联起来, track by $ index
。这是ng-repeat期间的内部迭代。
To go along with @cexbrayat's answer, if you don't have any IDs you can also just associated it and track by $index
. Which is an internal iteration # during an ng-repeat.
<div ng-repeat="channel in UIModel.channels track by $index"></div>
这篇关于Ang-ng重复引起闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文