Confirm navigation message using angularjs states (loading route before confirm message)

116 views
Skip to first unread message

Julie Kirwin

unread,
Aug 13, 2014, 2:13:17 PM8/13/14
to ang...@googlegroups.com
I posted this 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): 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): 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!





Reply all
Reply to author
Forward
0 new messages