0

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

bier hier
  • 20,970
  • 42
  • 97
  • 166

1 Answers1

3

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.

boyomarinov
  • 615
  • 4
  • 12
  • The thing is that the result is dependent on repairer. When I select a different repairer I would like getRequest to return a different request. – bier hier Feb 29 '16 at 20:35
  • In this case I would suggest that you pass the `getRequest` function as a callback to your directive and call it with the new repairer value, when it is changed. Roughly this will look like this: http://plnkr.co/edit/cUpMl3Lj8RCMMZIdAzbY?p=preview – boyomarinov Feb 29 '16 at 20:51