Error: [$rootScope:inprog] $digest already in progress, solution $rootScope.apply() not working

Here is my code in Login Controller…


        else if(!loginError)
                var response=angular.fromJson(resMat);
                    $rootScope.alertMsg(response.errorMsg,“Login Alert”,“OK”);

i am getting Error: [$rootScope:inprog] $digest already in progress ?
What should i do ?
i tried $rootScope.apply() but its not working

I am sharing the topi called "Solution to “Error: $digest already in progress” in AngularJS, please go through it, may be you will find it helpful…
Solution to “Error: $digest already in progress” in AngularJS


using .apply is in most cases a bad idea.
If there is already a refreshing cycle processing in the background, you will get exactly this error.

use $timeout(function () {}, 0); to hang into the next cycle.
Additional to that you read something about $digest.