Cancel $routeChangeStart event...

2,143 views
Skip to first unread message

Vili

unread,
Nov 27, 2012, 5:29:24 AM11/27/12
to ang...@googlegroups.com
Hi All,

I am listening $routeChangeStart event while view change....

MyApp.run(function ($rootScope) {
    $rootScope.$on('$routeChangeStart', function (event, scope, newRoute) {
       if(Some Condition){
         //code to stop $routeChangeStart
    });

});

I want to stop the $routeChangeStart event.

bjoern.we...@gmail.com

unread,
Dec 14, 2012, 11:43:28 AM12/14/12
to ang...@googlegroups.com

Anderson Aroeira Araujo

unread,
Dec 22, 2012, 5:54:15 PM12/22/12
to ang...@googlegroups.com
Hi Vili,

You can cancel the event.
I have implemented a solution like this:

$scope.hasChanges = function () {
return false;
}
var blockNavigation = true;
$scope.$on('$locationChangeStart', function(event, next, current) {
          if ($scope.hasChanges() & blockNavigation) {
            event.preventDefault();
            
            MessageService.showConfirmation(
                'Are you sure?', 
                MessageService.MessageOptions.YES_NO, 
                {'YES': function() {
                    blockNavigation = false;
                    $location.url($location.url(next).hash());
                    $rootScope.$apply();
                  },
                  'NO': function(){MessageService.clear(); $log.log('NO Selected')}});
          }
        });

Cheers
Reply all
Reply to author
Forward
0 new messages