Cancel $routeChangeStart event...

Showing 1-3 of 3 messages
Cancel $routeChangeStart event... Vili 11/27/12 2:29 AM
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.
Re: Cancel $routeChangeStart event... bjoern.we...@gmail.com 12/14/12 8:43 AM
Hi!

This is already discussed here:
https://groups.google.com/forum/#!msg/angular/BY2ekZLbnIM/fXEl7onSlN0J
https://groups.google.com/forum/?fromgroups=#!topic/angular/4_n3iqS7hOc

This issue addresses this problem as well:
https://github.com/angular/angular.js/issues/592

Regards
Björn

Am Dienstag, 27. November 2012 11:29:24 UTC+1 schrieb Vili:
Re: Cancel $routeChangeStart event... Anderson Aroeira Araujo 12/22/12 2:54 PM
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