Detecting navigations (changes in the path, for example)

38 views
Skip to first unread message

lightscalar

unread,
Feb 9, 2012, 2:53:54 PM2/9/12
to AngularJS
Howdy.

How would you detect when a user navigates to a different route. For
example, I have a user entering information in a text area associated
with one controller/template, I want to ensure the information is
saved when he navigates away from this form to another route.

I'd like to some how use beforeRouteChange to detect when the user is
navigating away, asynchronously save the form data, sending him on his
way.

Any ideas?

Thanks

lightscalar

unread,
Feb 9, 2012, 4:03:52 PM2/9/12
to AngularJS
AH. Answered my own question.

Just had to figure out how to listen to the event properly. A call to:

$rootScope.$on('$beforeRouteChange', function () {...})

in my controller did the trick.
Reply all
Reply to author
Forward
0 new messages