错误:rootScope:infdig已达到10个$ digest()迭代.堕胎 [英] Error: rootScope:infdig 10 $digest() iterations reached. Aborting

查看:57
本文介绍了错误:rootScope:infdig已达到10个$ digest()迭代.堕胎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有一些范围参数的自定义指令.我使用watchGroup来更改传入的参数.这是指令的一部分:

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" />

更新:经过更多的测试之后,我认为问题出在getRequest方法上,而不是watchGroup语句上.

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>>"}]]

这是一个矮胖的裁判: http://plnkr.co/edit/dSkjP1Vkvwd4fVauiFqa?p=预览

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

推荐答案

Angular 1.x摘要围绕脏检查构建.因此通常绑定到一个函数并不是一个好主意,因为角度将需要执行此函数以查看双向绑定值是否发生了变化.在这种情况下, getRequest()函数将成为有问题的函数.如果将 getRequest()的结果绑定到主控制器中的变量,然后将此变量绑定到指令,则应该很好.

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.

这篇关于错误:rootScope:infdig已达到10个$ digest()迭代.堕胎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆