ng-repeat中的角度无限$digest循环 [英] angular Infinite $digest Loop in ng-repeat

查看:26
本文介绍了ng-repeat中的角度无限$digest循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 ng-repeat 属性中调用函数,这是我的代码

示例 plnkr

html

<div ng-repeat='item in getGroupedRange() track by item.id'><span>{{item.val}}</span><span>{{item.abs}}</span><span>{{item.rel}}</span><span>{{item.cum}}</span>

js

$scope.getGroupedRange = function() {返回 [{价值:1,腹肌:1,相对:1,暨: 1,编号:123456}];};

当我打开控制台时,我注意到错误

 10 $digest() 迭代达到.中止!在最后 5 次迭代中触发观察者: [[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":9,"oldVal":8}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":10,"oldVal":9}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":11,"oldVal":10}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":12,"oldVal":11}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":13,"oldVal":12}]]

我的代码的主要目标是使用 ng-repeat 中的函数来计算每个事件循环中的数据

解决方案

找到解决方案:

 $scope.prev = null;$scope.getGroupedRange = function() {变量数据 = [{价值:1,腹肌:1,相对:1,暨: 1,编号:123456}];如果(angular.equals($scope.prev,数据)){返回 $scope.prev;}$scope.prev = 数据;返回数据;};

I want to call function in ng-repeat attribute, here is my code

example plnkr

html

<body ng-controller="mainCtrl">
  <div ng-repeat='item in getGroupedRange() track by item.id'>
    <span>{{item.val}}</span>
    <span>{{item.abs}}</span>
    <span>{{item.rel}}</span>
    <span>{{item.cum}}</span>
  </div>
</body>

js

$scope.getGroupedRange = function() {
    return [
      {
        val: 1,
        abs: 1,
        rel: 1,
        cum: 1,
        id: 123456
      }
    ];
  };

When I opened console I noticed the error

10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":9,"oldVal":8}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":10,"oldVal":9}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":11,"oldVal":10}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":12,"oldVal":11}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":13,"oldVal":12}]]

The main goal of my code is using function in ng-repeat for calculating data in each event loop

解决方案

Found the solution:

  $scope.prev = null;
  $scope.getGroupedRange = function() {
    var data = [{
      val: 1,
      abs: 1,
      rel: 1,
      cum: 1,
      id: 123456
    }];
    if (angular.equals($scope.prev, data)) {
      return $scope.prev;
    }
    $scope.prev = data;
    return data;
  };

这篇关于ng-repeat中的角度无限$digest循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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