Stack trace:
Error: $apply already in progress at Error () at beginPhase (file:///android_asset/www/built.min.js:7:22740) at Object.Scope.$a
We can use setTimeout function in such cases.
setTimeout
console.log('primary task'); setTimeout(function() { console.log('secondary task'); }, 0);
This will make sure that secondary task will be executed when execution of primary task is finished.