I posted this 
<http://stackoverflow.com/questions/25287715/confirm-navigation-message-using-angularjs-states?noredirect=1#comment39408502_25287715>
 
already on stack overflow, but wasn't really getting anywhere.

He is what the post says:

Following some examples I have found online, I am trying to implement a 
confirm navigation message when using back button or clicking on links and 
such on my site.

I am using angularjs states to switch between pages. I have followed what 
most all solutions said to do and put this code in my controller that 
encompasses all my settings to handle the confirm navigation:

$scope.$on('$locationChangeStart', function (event, next, current) {
        if (!confirm('Are you sure you want to leave this view?')) {
            //cancel leaving view2
            //works when clicking links, but doesn't work when using the back 
button
            event.preventDefault();
        }
    });



However, this is not working the way I expected. It seems its loading the 
new page before asking to confirm navigation

Here is a screenshot immediately after I click a new link (was on Trailers, 
clicked Shop Shifts): [image: enter image description here]

Here is a pic of what happens when I press cancel (see it still loads shop 
shit but shows trailers as selected link and url): [image: enter image 
description here]

Not really sure how to get it to display the message *before* the changing 
of pages. Has anyone ran into this issue before? Any ideas on how to fix 
it?? Thanks!





-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to