The problem is that it executes $digest on $rootScope twice in quick succession and throws an error when overlapping. To get around this, you can simply wrap both calls to $location.path() in $timeout , as was the first time in your plnkr example. This will make him wait for the completion of the $digest cycle.
You can also remove explicit calls to $rootScope.$apply() .
$rootScope.$on('FIRST_EVENT', function(event, msg) { $timeout(function() { $location.path("/view1"); }); }); $rootScope.$on('SECOND_EVENT', function(event, msg) { $timeout(function() { $location.path("/view2"); }); });
Note:
This code is based on the plnkr example, which is slightly different from the code in the original message.
Reference:
wait for the end of the cycle $ digest
source share