AngularJS外NG重复不登记在内部NG-重复手表 [英] AngularJS Outer ng-repeat not to register watches on inner ng-repeat

查看:128
本文介绍了AngularJS外NG重复不登记在内部NG-重复手表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题的关系 - 角JS会消耗更多的浏览器内存

This is in relation with my question - Angular JS consumes more browser memory

我在这里的问题是我需要嵌套的NG-重复和嵌套NG-重复消耗了,因为被登记在册的手表更多的内存。

My problem here is I need nested ng-repeats and the nested ng-repeats consumes more memory because of more watches being registered.

<table>
  <thead><td>Id</td><td>Name</td><td>Ratings</td></thead>
  <tbody>
   <tr ng-repeat="user in users | orderBy:'name' | limitTo:display_limit">
    <td>{{user.id}}</td>
    <td>{{user.name}}</td>
    <td><div ng-repeat="item in items | orderBy:'rating' | limitTo:inner_display_limit">{{item.rating}}</div></td>
   </tr>
  </tbody>
</table>

下面在我的情况下,外NG-重复和内NG重复操作上可以高达1000而作为@Liviu对象的数量在回答指出,各外NG-的重复注册观看在内NG重复和导致正在使用的内存量消耗品。有没有一种方法,我们可以避免从内部的登记表外NG重复通过编写自己的自定义指令?

Here in my case, the number of objects that outer ng-repeat and inner ng-repeat operates on can go upto 1000. And as @Liviu pointed in the answer,each of the outer ng-repeat registers watch on the inner ng-repeat and that leads to consumable amount of memory being used. Is there a way we can avoid the outer ng-repeat from registering watches on inner ones by writing our own custom directive?

我的情况是内外NG-重复,我显示初始的50个项目和滚动,如果滚动达到相应的DOM结束时,我50更新的限制,所以,在未来50个项目获得显示。

My case is in both inner and outer ng-repeats, I display the initial 50 items and on scroll, if the scroll reaches the end of the corresponding DOM, I update the limit by 50, so that the next 50 items gets displayed.

任何帮助很多AP preciated!

Any help is much appreciated!

推荐答案

您可以写一个指令,既需要用户项目为绑定属性(尤其是因为它看起来像你的内循环是从外层独立),然后手动窝两个循环,将内容添加到DOM,再加上增加一个滚动监听器的每个元素。它更硬编码的方式,但少了很多观察家。

You could write a directive that takes both users and items as bindings attributes (especially because it seems like your inner loop is independant from the outer one), then manually nest two loops that would add content to the DOM, plus adding a scroll listener to each element. It's more hard-way coding but a lot less watchers.

这篇关于AngularJS外NG重复不登记在内部NG-重复手表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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