Angular JS错误:仅在IE 10和IE 11中出现[$rootScope:infdig]

Angular JS Error: [$rootScope:infdig] in IE 10 and IE 11 only

本文关键字:IE rootScope infdig 错误 JS 仅在 Angular      更新时间:2023-09-26

我正在运行Angular JS v1.4.7,该应用程序在Internet Explorer 10和11中完全崩溃(我们不支持旧版本)。当我检查控制台时,我看到:Error: [$rootScope:infdig],这里对此进行了一些解释。

它在其他浏览器中运行完美,没有任何错误。

经过大量的尝试和错误,我能够将问题隔离为其中一个指令中的一个逻辑位,我已经简化了它:

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();
            });
        }
    };
});

我可以通过注释setLogoDimensions:scope.inlinesvg = $('<div>').append(svg.clone()).html(); 的最后一行来打开/关闭这个问题

来自Angular文档

当应用程序的模型变得不稳定并且每个$digest循环都会触发状态更改和随后的$digest周期Angular检测到这种情况并防止无限循环避免导致浏览器变得无响应。例如,这种情况可以通过在路径上设置手表来发生并且随后在值改变时更新相同的路径。

$scope$watch('fo',function(){$scope.foo=$scope.foo+1;});

在这里,您正在您的范围内修改您的inlinesvg模型$监视inlinesvg(抛出了您的setLogoDimensions()函数)。你不能这样做