的$性能插值VS NG重复和一次性绑定 [英] performance of $interpolate vs ng-repeat and one time binding

查看:116
本文介绍了的$性能插值VS NG重复和一次性绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前的http://www.bin$p$pss.com/tutorial/speeding-up-angular-js-with-simple-optimizations/135

被写入,对于指令最好是比NG-重复使用插值:

it is written that for directives it is better to use interpolate than ng-repeat:

NG的重复指令是最有可能的罪魁祸首
  性能问题,这意味着它很容易被滥用。一个
  与$范围对象数组,这锤NG重复可能交易
  在$消化周期的表现。

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.

例如,代替使用纳克重复渲染全球导航,
  我们可以使用$插值提供商来创建我们自己的导航
  使我们的模板对一个对象,并将其转换成DOM节点。

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我们可以使用纳克重复与时间绑定来达到同样的效果。

When using angular 1.3 we could use ng-repeat with one time bindings to achieve the same result.

难道还要更好地使用$插值用于这一目的?

Is it still better to use $interpolate for this purpose?

推荐答案

我建议你 bindonce 为这一点,如果你是针对< 1.3,只需添加 bindonce 旁边的 NG-重复,改变你的纳克 - * 指令来博 - * 在重复的部分。它基本上做同样的事情为1.3的一次绑定。

I'd recommend bindonce for this if you're on <1.3, just add bindonce next to your ng-repeat and change your ng-* directives to bo-* in the repeating part. It basically does the same thing as 1.3's one time bindings.

如果您quetion你的意思是你应该使用 $插值而不是一个时间1.3绑定,我会说去与 NG-重复有一次,因为结合没有任何观察家你慢下来,这是一个很大的可读性。尽管 NG-重复还是创建子范围,性能差异是微不足道的,如果你没有做这些事情的作用域。

If by your quetion you meant should you use $interpolate instead of one time binding in 1.3, I'd say go with ng-repeat with one time binding since there aren't any watchers to slow you down and it's a lot more readable. Even though ng-repeat still creates the child scopes, the performance difference is negligible if you're not doing anything in those scopes.

从经验,你会在之前 $渲染这么多因素消化打在你的浏览器性能问题如果你不检查观察家,甚至有很多成为一个问题儿童范围。

From experience you'll hit performance issues in your browser in rendering so many elements before $digest becomes an issue if you're not checking watchers, even with a lot of child scopes.

这篇关于的$性能插值VS NG重复和一次性绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆