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? –