1

My application has a dashboard with some panels, each one with a chart.(I use Angular-Chart.js) Each panel is a different custom directive.

I have TickService with a global tick, broadcasted each 1sec

 function sendUpdateTich()
    {      
     $rootScope.$broadcast("TICK_UPDATE_TIME");
     $timeout(sendUpdateTich, 1000);
    }

Each directive listens for the tick, to update their own graphics.

    $scope.$on("TICK_UPDATE_TIME", function (event, data) 
                            {
                             /* update chart's data */
                             //  $scope.$apply();
                            });

Even if, by my own logic, I would use $scope.$apply() to refresh the directives' charts, I commented it out since it's useless, charts are already refreshed by them selves.

Anyway sometimes I've got this error:

Error: [$rootScope:inprog] $apply already in progress
http://errors.angularjs.org/1.5.3/$rootScope/inprog?p0=%24apply
http://localhost:8100/lib/ionic/js/ionic.bundle.js:13443:32
beginPhase@http://localhost:8100/lib/ionic/js/ionic.bundle.js:30758:31
$apply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:30498:21
http://localhost:8100/js/orecchioDirective.js:25:40
$broadcast@http://localhost:8100/lib/ionic/js/ionic.bundle.js:30723:33
stopCheckinProximity@http://localhost:8100/js/callTimeService.js:226:26
stopChecking@http://localhost:8100/js/callTimeService.js:163:25
setEnded@http://localhost:8100/js/statusCallService.js:62:34
endCall@http://localhost:8100/js/controllers.js:319:31
fn
http://localhost:8100/lib/ionic/js/ionic.bundle.js:65429:21
$apply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:30500:30
http://localhost:8100/lib/ionic/js/ionic.bundle.js:65428:19
defaultHandlerWrapper@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16792:15
eventHandler@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16780:23
dispatchEvent@[native code]
triggerMouseEvent@http://localhost:8100/lib/ionic/js/ionic.bundle.js:2953:20
tapClick@http://localhost:8100/lib/ionic/js/ionic.bundle.js:2942:20
tapMouseUp@http://localhost:8100/lib/ionic/js/ionic.bundle.js:3018:13

It doesn't occur at every tick, but just sometimes, I think (I don't know, but I just think..) according to some other $broadcasted event. I don't have any $scope.$apply, $rootScope.$apply neither $scope.$refresh, anywhere in the code. What's the problem?

[UPDATE 1] According to this, $timeout() does the $apply() call for us so we don't have to. Since I have others $timeout() in Services, is it possible that they messy together?

DeLac
  • 1,068
  • 13
  • 43
  • 1
    Possible duplicate of [$apply already in progress error](https://stackoverflow.com/questions/18626039/apply-already-in-progress-error) – Ramesh Rajendran Oct 05 '17 at 12:05
  • Try using `$interval` every 1 second instead of a `$timeout` that recursively calls that function. There may be some issues with how you call `$timeout`. – bamtheboozle Oct 05 '17 at 12:05
  • @RameshRajendran I don't think it's a duplicated question because I don't use any $scope.$apply, as the other user of that question does. Maybe it's a different problem. – DeLac Oct 05 '17 at 12:11
  • are you sure you need an excplicit call to apply()? post the code inside the apply – Karim Oct 05 '17 at 12:16
  • no, I don't use $apply() anywhere in the code. I just use $scope and $rootScope to $broadcast and listen $on my custom events – DeLac Oct 05 '17 at 12:17
  • @DeLac Instead of making people guess, create a minimal working example with the issue and you will start getting solid answers! – Naren Murali Oct 07 '17 at 07:54

0 Answers0