[英]Angular JS Error: [$rootScope:infdig] in IE 10 and IE 11 only
I'm running Angular JS v1.4.7 and the app completely crashes in Internet Explorer 10 and 11 (we don't support older). 我正在运行Angular JS v1.4.7,并且该应用程序在Internet Explorer 10和11中完全崩溃(我们不支持旧版本)。 When I check the console I see: Error: [$rootScope:infdig]
which is somewhat explained here . 当我检查控制台时,我看到: Error: [$rootScope:infdig]
, 这里有所解释。
It runs perfectly with no errors in other browsers. 它运行完美,在其他浏览器中没有错误。
After a lot of trial and error I was able to isolate the problem to a single bit of logic in one of the directives, which I've simplified: 经过大量的反复试验后,我能够将问题与其中一个指令中的一个逻辑区分开来,我已将其简化为:
tsApp.directive('svgIcon', function($timeout) {
return {
restrict: 'E',
replace: true,
scope: {
inlinesvg: '=',
orientation: '@',
themeid: '@',
scale: '@',
verticalAlign: '@'
},
template: '<span ng-bind-html="inlinesvg | unsafe"></span>',
link: function(scope, element, attrs) {
/* @TODO Synchronize with similar function in Mode Icon directive */
/* Function updates inlinesvg to avoid flicker */
scope.setLogoDimensions = function() {
/* Obtain svg attributes */
var svg = angular.element(scope.inlinesvg);
/* ... */
/* Reinsert raw svg with jQuery conversion */
scope.inlinesvg = $('<div>').append(svg.clone()).html();
};
/* Resize if new inlinesvg */
scope.$watch('inlinesvg', function() {
scope.setLogoDimensions();
});
}
};
});
I can turn the problem on/off by commenting out the final line of setLogoDimensions
: scope.inlinesvg = $('<div>').append(svg.clone()).html();
我可以通过注释掉setLogoDimensions
的最后一行来打开/关闭问题: scope.inlinesvg = $('<div>').append(svg.clone()).html();
From Angular doc 来自Angular doc
This error occurs when the application's model becomes unstable and each $digest cycle triggers a state change and subsequent $digest cycle. 当应用程序的模型变得不稳定并且每个$摘要周期触发状态更改和随后的$摘要周期时,会发生此错误。 Angular detects this situation and prevents an infinite loop from causing the browser to become unresponsive. Angular检测到这种情况并防止无限循环导致浏览器无响应。 For example, the situation can occur by setting up a watch on a path and subsequently updating the same path when the value changes. 例如,可以通过在路径上设置监视并随后在值更改时更新相同路径来实现这种情况。
$scope.$watch('foo', function() { $scope.foo = $scope.foo + 1; }); $ scope。$ watch('foo',function(){$ scope.foo = $ scope.foo + 1;});
Here, you are modifiying your inlinesvg model inside your scope.$watch of inlinesvg (threw your setLogoDimensions() function). 在这里,您要修改范围内的inlinesvg模型。$ watch of inlinesvg(抛出setLogoDimensions()函数)。 You can't do that 你不能这样做
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.