Stack trace:
Error: $apply already in progress
at Error ()
at beginPhase (file:///android_asset/www/built.min.js:7:22740)
at Object.Scope.$a
If scope must be applied in some cases, then you can set a timeout so that the $apply is deferred until the next tick
setTimeout(function(){ scope.$apply(); });
or wrap your code in a $timeout(function(){ .. }); because it will automatically $apply the scope at the end of execution. If you need your function to behave synchronously, I'd do the first.