First, don't you mean $apply()
? Second, why would you use $rootScope
to kick off a digest cycle instead of $scope
within the controller. Third, I don't think you're using the correct logic to achieve the desired functionality. the event $locationChangeStart
signals the start of a location change within the Angular Application. $window.confirm()
will halt that navigation temporarily while calling event.preventDefault()
will stop the navigation all together. Therefore, you should wait for confirmation from $window.confirm()
. If the use clicks cancel, proceed
will be false. If proceed
is false, call event.preventDefault()
, otherwise, do nothing. There is absolutely no need for you to call $location.path()
when the application is already in the process of navigating to that page.
I've created a Plunk of the scenario here: