Hi All,
I'm not really an AngularJS guru, but am using it for a project and am stumped.
I'm trying to figure out how to detect a URL change with only a user entering the url through the menu bar. I have looked into solutions on the web using $routeChangeSuccess, but that doesn't seem like an option, since the application I am working on is making use of ui-router instead, and the two seem to conflict. It seems like my option is to use $stateChangeSuccess, or $locationChangeSuccess, but those events capture both user clicks *and* page refreshes via the address bar.
Is there some way to do a check to differentiate between what event was fired?
I've done something like this:
.run(['$rootScope','ngDialog','$document',$urlRouter', function($rootScope,ngDialog,$document,$urlRouter) {
$document.on('click',function() {
console.log('clicked')
})
$rootScope.$on('$locationChangeSuccess',function(e) {
console.log('location change')
});
})
This gets me somewhere, but not enough. I notice the sequence of events seems to be that 'location change' shows up first, and then 'clicked' shows up next in the console. It would be great if I could figure out a reverse order, so I could differentiate between a click and address bar change manually, perhaps by setting a flag when the click is fired and then checking that via $locationChangeSuccess. Basically I'm trying to tell the difference between needing to force a page reload (via manual URL enter), vs clicking (don't force reload).
Has anyone been able to solve something like this? A google search found topics that are somewhat along the lines, but I'm coming up short with an actual solution.
Thanks,
Scott Diorio