AngularJS Wiki - Anti-Patterns states the following:
Don't do
if (!$scope.$$phase) $scope.$apply()
, it means your$scope.$apply()
isn't high enough in the call stack.
And I kind of understand this. There is a built in logic that determines when what needs to be executed. And when an external developer, without direct insigt in the runtime executions of different procedures, determines what should run where, it counteracts the framework.
But I am currently uploading a large file where the upload progress is displayed through a progress bar. The library I use (resumableJS) in turn has an event called fileProgress, that is called when the upload is progressing. If I do nothing during that event, the bar is not updating. If I put $scope.$apply()
there, the bar is updated accordingly, but I get the digest and/or apply already in progress error. Finally, with the help of the $$phase
check I get the best of both worlds, an updated progress bar without any errors.
So what is the correct alternative to get my bar updated while not interfering with the angulars processing order?