本文介绍了滞留在无限循环NG-重复angularfire 8.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚为什么这个NG-repeat语句运行无限。
Item.members具有2的长度,并包含用户id =真

I'd like to figure out why this ng-repeat statement runs infinite.Item.members has a length of 2 and contains userIds = true

<script type="text/ng-template" id="items_renderer.html">
     <label>
       <span class="team-description" ng-show="!item.editing">{{item.name}}</span>

       <label ng-repeat="memberId in item.members">
         <span>{{ getMember(memberId) }}</span>
       </label>
     </label>
</script>


 <div ui-tree="options" class="teamlist">
     <ol ui-tree-nodes ng-model="teams" class="panel-teams">
         <li ui-tree-node ui-tree-handle
          ng-repeat="item in teams"
          ng-include="'items_renderer.html'">
         </li>
     </ol>
 </div>

$scope.getMember = (memberId) ->
  memberobj = fbutil.syncObject('users/' + memberId)
  memberobj.$loaded().then (ref) ->
    $scope.teamUser.push ref.name
    console.log $scope.teamUser
    return $scope.teamUser

它只是将继续运行无限期的。

It will just keep running indefinite.

[斯文Woldt,斯文Woldt,斯文Woldt,斯文Woldt,斯文Woldt,斯文Woldt,斯文Woldt,斯文Woldt,斯文Woldt,雅虎,雅虎,雅虎,雅虎,雅虎,雅虎,雅虎,雅虎,雅虎,斯文Woldt,雅虎,斯文Woldt,雅虎,斯文Woldt,雅虎,...]

["Sven Woldt", "Sven Woldt", "Sven Woldt", "Sven Woldt", "Sven Woldt", "Sven Woldt", "Sven Woldt", "Sven Woldt", "Sven Woldt", "Yahoo", "Yahoo", "Yahoo", "Yahoo", "Yahoo", "Yahoo", "Yahoo", "Yahoo", "Yahoo", "Sven Woldt", "Yahoo", "Sven Woldt", "Yahoo", "Sven Woldt", "Yahoo",…]

所以我怎么可能会限制这种只返回[斯文Woldt,雅虎]

So how could I restrict this to only return ["Sven Woldt", "Yahoo"]

感谢您的帮助!

推荐答案

每当角呈现此&LT;跨度&GT; {{getMember(MEMBERID)}}&LT; / SPAN&GT; 你最终(重新)加载,从火力地堡,这反过来又触发重新渲染成员。

Every time Angular renders this <span>{{ getMember(memberId) }}</span> you end up (re)loading that member from Firebase, which in turn triggers a re-render.

您流程是这样的:


  1. 角开始渲染视图

  2. 角通话 getMember

  3. getMember 开始从火力地堡加载数据

  4. 在某些时候,数据加载和你的然后执行

  5. 您推一个新的对象到 $范围,这反过来

  6. 告诉角度重新渲染你的看法,所以我们回到第1步

  1. Angular starts to render your view
  2. Angular calls getMember
  3. getMember starts loading the data from Firebase
  4. At some point the data is loaded and your then is executed
  5. You push a new object onto the $scope, which in turn
  6. Tells Angular to re-render your view, so we go back to step 1

getMember code应该检查是否以前已经加载此成员。如果有,它不应该试图重新加载它 - 或者至少不会将其推入 $范围再次

Your getMember code should check if it has already loaded this member before. If it did, it shouldn't try to reload it - or at least not push it into the $scope again.

这篇关于滞留在无限循环NG-重复angularfire 8.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 14:50