title: Error: $digest already in progress
body: <p>I'm getting this error while trying to call </p>
  
  <pre><code>        function MyCtrl1($scope, $location, $rootScope) {
        $scope.$on('$locationChangeStart', function (event, next, current) {
          event.preventDefault();
          var answer = confirm("Are you sure you want to leave this page?");
          if (answer) {
            $location.url($location.url(next).hash());
            $rootScope.$apply();
          }
        });
      }
  
  MyCtrl1.$inject = ['$scope', '$location', '$rootScope'];
  </code></pre>
  
  <p>Error is</p>
  
  <pre><code>Error: $digest already in progress
  </code></pre>