错误:[$ rootScope:infdig] 10 $ digest()迭代达成。堕落错误的事情

时间:2014-07-29 19:18:49

标签: angularjs

出现此错误:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["fn: $locationWatch; newVal: 8; oldVal: 7"],["fn: $locationWatch; newVal: 9; oldVal: 8"],["fn: $locationWatch; newVal: 10; oldVal: 9"],["fn: $locationWatch; newVal: 11; oldVal: 10"],["fn: $locationWatch; newVal: 12; oldVal: 11"]]
http://errors.angularjs.org/1.2.21/$rootScope/infdig?p0=10&p1=%5B%5B%22fn%3…2fn%3A%20%24locationWatch%3B%20newVal%3A%2012%3B%20oldVal%3A%2011%22%5D%5D
    at chrome-extension://jiflmhpffanabaldnciipnblmfjcjado/bower_components/angular/angular.js:78:12
    at Scope.$digest (chrome-extension://jiflmhpffanabaldnciipnblmfjcjado/bower_components/angular/angular.js:12510:19)
    at Scope.$apply (chrome-extension://jiflmhpffanabaldnciipnblmfjcjado/bower_components/angular/angular.js:12736:24)
    at HTMLHtmlElement.<anonymous> (chrome-extension://jiflmhpffanabaldnciipnblmfjcjado/bower_components/angular/angular.js:9811:22)
    at chrome-extension://jiflmhpffanabaldnciipnblmfjcjado/bower_components/angular/angular.js:2843:10
    at forEach (chrome-extension://jiflmhpffanabaldnciipnblmfjcjado/bower_components/angular/angular.js:325:18)
    at HTMLHtmlElement.eventHandler (chrome-extension://jiflmhpffanabaldnciipnblmfjcjado/bower_components/angular/angular.js:2842:5) angular.js:10023
Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["fn: $locationWatch; newVal: 8; oldVal: 7"],["fn: $locationWatch; newVal: 9; oldVal: 8"],["fn: $locationWatch; newVal: 10; old...<omitted>...5D 

当我取消注释此代码时:

$scope.$watch(function(){return document.querySelectorAll("span.joggleEmail")},function(newValue, oldValue){
            var emails = document.querySelectorAll("span.joggleEmail")

            angular.forEach(emails, function(span){
                // unbind the click, this is important for `mailto:`
                angular.element(span).unbind("click");

                angular.element(span).bind("click", function(){
                    console.log("Searching...");
                    $scope.$broadcast("searchServer", this.innerHTML);
                });
            })
        }, true)

不知道为什么以及我在哪里与$location有任何关系,因为它给了我这个错误。知道如何调试这个问题吗?

1 个答案:

答案 0 :(得分:0)

有时观看函数会产生导致这些情况的奇怪行为。我对querySelectorAll不熟悉,但可能是它返回的任何东西都经常变化。如果可以观察变量而不是函数,那么可以解决问题。