我在 Angularjs 中收到以下错误:
"Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["fn: parentValueWatch; newVal: {\"x\":0,\"y\":0}; oldVal: {\"x\":0,\"y\":0}"],["fn: parentValueWatch; newVal: {\"x\":0,\"y\":0}; oldVal: {\"x\":0,\"y\":0}"],["fn: parentValueWatch; newVal: {\"x\":0,\"y\":0}; oldVal: {\"x\":0,\"y\":0}"],["fn: parentValueWatch; newVal: {\"x\":0,\"y\":0}; oldVal: {\"x\":0,\"y\":0}"],["fn: parentValueWatch; newVal: {\"x\":0,\"y\":0}; oldVal: {\"x\":0,\"y\":0}"]]
newVal
和 oldVal
日志都是相同的。根据How to Troubleshoot Angular "10 $digest() iterations reached" Error ,当值改变时应该抛出错误。
这是我的应用代码:
$scope.getCommentLocation = function(comment) {
console.log("TEST");
if (comment == undefined) { // This is all that gets returned every time
return {
x: 0,
y: 0
};
}
$range = getRangeObjectForComment(comment);
position = $range.offset();
window_position_y = position.top - $('#main-text_ifr').contents().find('body').scrollTop() + frameposition.top + $range.height() / 2;
window_position_x = position.left + frameposition.left + $range.width() / 2;
return {
x: window_position_x,
y: window_position_y
};
};
这是jade代码(Jade是一种html模板语言):
location="getCommentLocation(commentEditor.activeComment)"
最佳答案
以下代码将始终创建一个新对象并返回它。
return {
x: 0,
y: 0
};
使用 $scope.origin 类型的引用变量,该变量仅在 $scope.getCommentLocation
之外定义一次。
$scope.origin ={x:0, y:0};//永远不要在任何地方重新创建它,只使用原始引用
并使用return $scope.origin
关于javascript - $digest 错误,没有模型更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24068894/