【发布时间】:2016-09-25 16:22:02
【问题描述】:
假设您有一个非常大的导航,大约有 15 个嵌套级别,例如:
var app = angular.module("myApp", []);
app.controller("HomeCtrl", ["$scope", function($scope) {
this.entries = [{
"title": "test",
"entries": [{
"title": "sub-test",
"entries": [{
"title": "sub-test",
"entries": [{
"title": "sub-test",
"entries": [{
"title": "sub-test",
"entries": [{
"title": "sub-test",
"entries": [{
"title": "sub-test",
"entries": [{
"title": "sub-test",
"entries": [{
"title": "sub-test",
"entries": [{
"title": "sub-test",
"entries": [{
"title": "sub-test",
"entries": [{
"title": "sub-test",
"entries": [{
"title": "sub-test"
}]
}]
}]
}]
}]
}]
}]
}]
}]
}]
}]
}]
}];
return this;
}]);
您正在使用ng-repeat 迭代这些:
<script type="text/ng-template" id="entryTree">
<span>{{ entry.title }}</span>
<ol ng-if="entry.entries">
<li ng-repeat="entry in entry.entries" ng-include="'entryTree'"></li>
</ol>
</script>
<div ng-controller="HomeCtrl as ctrl">
<ol>
<li ng-repeat="entry in ctrl.entries" ng-include="'entryTree'"></li>
</ol>
</div>
然后会抛出$rootScope:infdig 错误:10 $digest() iterations reached. Aborting!。我知道这里有几个类似的问题(例如this one)。但就我而言,我没有从控制器返回动态值,也没有使用动态 getter,我只是将值静态保存在控制器中。
这是什么原因?解决方案会是什么样子?
【问题讨论】:
标签: angularjs navigation ng-repeat navigationbar