由于angularjs中的ng-repeat而导致错误

时间:2013-01-24 11:33:30

标签: angularjs

我使用嵌套的ng-repeat在html页面中显示我的数据。

它正在抛出错误

Error: Error: 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations

但是这个错误不影响我的功能。我正在寻找这个问题的答案,但我没有得到正确的答案,我在这里发布了这个问题。

我不知道我的json数据结构是否会导致此错误,但我无法更改其结构。

这是我的样本json数据

    //In controller
for (var i = 1; i <= 31; i++) {
$scope.daysofmonth.push({day:i});    // daysofmonth.day->1,2,3...
}
for(var j=0; j<$scope.daysofmonth.length; j++) {
$scope.daysofmonth[j].events = [     // creating 31 arrays for events
    {"name":"T", "count":0,"data":[{
         "startDate":"01/25/2013",
         "startTime":"00:00",
         "endDate":"01/26/2013",
         "endTime":"00:00",
         "type":"m",
         "status":"Not Started",
         "title":"Demo to Client",
         "description":"Application demo"
             }]},
    {"name":"I", "count":0,"data":[...]} // same as previous
    ];
 //left some of the business logic
}

    //In html file
    <div class="{{box | today:year+'-'+month+'-'+dayofmonth.day:dayofmonth.day}}"  ng-repeat="dayofmonth in daysofmonth" >
    <span class="days">{{ dayofmonth.day }}</span>
    <span class="events-list">
            <div ng-repeat="eve in dayofmonth.events" >   
                {{ eve.count + eve.name }} 
        </div>
    </span>
    </div>

任何人都可以告诉我导致此错误的原因以及解决方法吗?

3 个答案:

答案 0 :(得分:1)

JSON无效。此外,您的模板不会输出任何可见的内容,除非您在转发器中添加了一些绑定标记,例如{{ Company.Company.id }}

答案 1 :(得分:0)

这可能是因为您正在ng-repeat内的视图中初始化对象。因为那个我有类似的问题。请看这个链接

Error: 10 $digest() iterations reached. Aborting! with dynamic sortby predicate

答案 2 :(得分:0)

正如其他人已经说过的那样,数据无效。虽然它可能是有效的JSON,但它不是有效的javascript。我根据数据结构掀起了一个吸尘器示例,清理了有效的javascript,并且我没有嵌套ng重复的任何错误。

当然,只有两个,因为你已经在上面的代码片段中显示了所有内容。但它适用于这两个,并且应该与其他嵌套重复一样好用。

http://plnkr.co/edit/z36YclsngdX9HozgdUkQ?p=preview