3

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

它在其他浏览器中完美无误地运行。

大量的试验和错误,我能够将问题隔离到逻辑的单个比特在指令中的一个,其中我已经简化的后:

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

回答

1

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

在这里,你是modifiy在你的作用域内嵌入你的inlinesvg模型$ inlinesvg(扔你的setLogoDimensions()函数)。 你不能这样做

+0

任何想法为什么这个错误只发生在IE 11而不是Firefox 52.3? –