Error: rootScope:infdig 10 $digest() iterations reached. Aborting

一曲冷凌霜 提交于 2019-12-12 05:38:35

问题


I have created a custom directive that takes some scope parameters. I used a watchGroup for incoming parameters change. This is part of the directive:

 scope.$watchGroup(['repairer', 'initial'], function() {

          if (scope.initial) {
            scope.Repairer = scope.initial;

          } else {
            scope.Repairer = scope.repairer;
          }

          console.log('scope.Repairer value:', scope.Repairer);

          if (scope.Repairer) {

            console.log('wooohoo calling scriptservice');

            scriptingService.getScript(scope.request).then(function(scripts) {
              scope.scripts = scripts;
            });
          } else {
            scope.scripts = null;
          }
        });

I am using the directive as follows in my page:

<scripting repairer="repairer" request="getRequest(repairer,initial)" initial="initial" />

UPDATE: after playing around a bit more I think the issue is with the getRequest method and not the watchGroup statement.

Why am I getting this error now:

   Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: regularInterceptedExpression","newVal":{"allocationProcess":"direct","allocationSource":"internal","brand":"popie","includeSegment":false,"relationship":"lol","ruralSearch":true,"state":"VIC"},"oldVal":{"allocationProcess":"direct","allocationSource":"internal","brand":"popie","includeSegment":false,"relationship":"lol","ruralSearch":true,"state":"VIC"}}],[{"msg":"fn: regularInterceptedExpression","newVal":{"allocationProcess":"direct","allocationSource":"internal","brand":"popie","includeSegment":false,"relationship":"lol","ruralSearch":true,"state":"VIC"},"oldVal":"<<already seen>>"}],[{"msg":"fn: regularInterceptedExpression","newVal":{"allocationProcess":"direct","allocationSource":"internal","brand":"popie","includeSegment":false,"relationship":"lol","ruralSearch":true,"state":"VIC"},"oldVal":"<<already seen>>"}],[{"msg":"fn: regularInterceptedExpression","newVal":{"allocationProcess":"direct","allocationSource":"internal","brand":"popie","includeSegment":false,"relationship":"lol","ruralSearch":true,"state":"VIC"},"oldVal":"<<already seen>>"}],[{"msg":"fn: regularInterceptedExpression","newVal":{"allocationProcess":"direct","allocationSource":"internal","brand":"popie","includeSegment":false,"relationship":"lol","ruralSearch":true,"state":"VIC"},"oldVal":"<<already seen>>"}]]

Here is a plunker ref: http://plnkr.co/edit/dSkjP1Vkvwd4fVauiFqa?p=preview


回答1:


Angular 1.x digest is build around dirty-checking. So usually binding to a function is not such a good idea, because then angular will need to execute this function in order to see if there has been a change in the two-way bound value or not. In this case the getRequest() function will be the function in question. If you bind the result of getRequest() to a variable in your main controller and then bind this variable to your directive, you should be good to go.



来源:https://stackoverflow.com/questions/35708487/error-rootscopeinfdig-10-digest-iterations-reached-aborting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!