加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:38:26 所属栏目:安全 来源:网络整理
导读:在 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 easi
在 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之前渲染这么多元素会成为一个问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读