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?