angularjs – $interpolate vs ng-repeat和一次性绑定的性能

前端之家收集整理的这篇文章主要介绍了angularjs – $interpolate vs ng-repeat和一次性绑定的性能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
http://www.binpress.com/tutorial/speeding-up-angular-js-with-simple-optimizations/135

据说,对于指令,使用插值比使用ng-repeat更好:

The ng-repeat directive is most likely the worst offender for
performance concerns,which means it can easily be abused. An
ng-repeat likely deals with Arrays of $scope Objects and this hammers
the $digest cycle’s performance.

For example,instead of rendering a global navigation using ng-repeat,
we could create our own navigation using the $interpolate provider to
render our template against an Object and convert it into DOM nodes.

当使用角度1.3时,我们可以使用ng-repeat和一次时间绑定来实现相同的结果.

为此目的使用$interpolate更好吗?

解决方法

如果您打开< 1.3,我建议使用 bindonce,只需在ng-repeat旁边添加bindonce,并在重复部分中将ng- *指令更改为bo- *.它基本上与1.3的一次性绑定完全相同.

如果您的意思是你的意思是你应该使用$interpolate而不是1.3中的一次时间绑定,我会说使用ng-repeat进行一次时间绑定,因为没有任何观察者会减慢你的速度并且它更具可读性.尽管ng-repeat仍然会创建子范围,但如果您在这些范围内没有执行任何操作,则性能差异可以忽略不计.

根据经验,如果你没有检查观察者,即使有很多子范围,你也会在浏览器中遇到性能问题,因为在$digest之前渲染这么多元素会成为一个问题.

猜你在找的Angularjs相关文章