AngularJS错误: $rootScope:infdig

标签 angularjs

以下AngularJS代码出现错误。

test01.js

var MyApp = angular.module('moduleName', []);
MyApp.controller('NameCtrl', ['$scope', function ($scope) {
    $scope.list = function() {

        return {"1": {id: 1, name: "aaa"},
                "2": {id: 2, name: "bbb"},
                "3": {id: 3, name: "ccc"}};
    }
}]);

test01.html

<div class="container">
    <div class="jumbotron">
        <h2>test01!</h2>
    </div>
    <div ng-controller="NameCtrl">
        <table class="table table-striped">
            <tr ng-repeat="list in list()">
                <td ng-repeat="nake in list">{{nake.id}}</td>
            </tr>
        </table>
    </div>
</div>

错误

Error: [$rootScope:infdig] http://errors.angularjs.org/1.3.1/$rootScope/infdig?p0=10&p1=%5B%5B%22fn%3A…Breturn%20z(e)%3Ff%3Ae%7D%3B%20newVal%3A%2034%3B%20oldVal%3A%2031%22%5D%5D
Uncaught Error: [$rootScope:infdig] http://errors.angularjs.org/1.3.1/$rootScope/infdig?p0=10&p1=%5B%5B%22fn%3A…Breturn%20z(e)%3Ff%3Ae%7D%3B%20newVal%3A%2034%3B%20oldVal%3A%2031%22%5D%5D angular.js:14078

或者数组嵌套错误? 原因未知。

最佳答案

我认为在 ngRepeat 中使用函数会让 angularjs 为它找到的每个元素调用它,从而使其进入无限循环。

您可以执行以下操作:

<table class="table table-striped" ng-init="list = list()">
    <tr ng-repeat="element in list">

所以它会起作用。 还有另一个问题。 list() 函数返回一个对象,而不是数组。 另外,第二个 ngRepeat 不会破坏代码,但没有用,因为没有任何嵌套数组。 这是一个工作 fiddle : http://jsfiddle.net/5sek867y/2/

关于AngularJS错误: $rootScope:infdig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26753014/

相关文章:

javascript - 使用 AngularJS 路由器加载 404 状态

javascript - 如何处理字符串中的一些 HTML 标签(不是全部)?

javascript - AngularJS 在引导后添加依赖项

angularjs - 在 $digest 之后延迟 angularjs 监视执行(引发 DOM 事件)

javascript - 我连续有三列,但是当我将值放入第一列时,它会自动转到所有其他两列

javascript - AngularJS 最佳实践 : What's the best way to 'change templates' based on object data?

javascript - 使用 Ionic - 无法正确加载 Firebase - 错误 : Module 'firebase' is not available

javascript - 我应该如何使用 angularjs 取消选择 html 页面中已选择的复选框?

javascript - Protractor 等待元素超时

javascript - 防止 ng-repeat 中出现重复值 (AngularJS)