问题
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