The application uses angularjs. I have a navigation bar which opens pages and also another UI which also opens the same pages(same links).
I am using $locationChangeStart to toggle open the sub-menu in the navbar when I open a page from the other UI.
When I open the same page from the from the navigation bar, the toggle happens and the sub-menu of navbar closes.
$rootScope.$on("$locationChangeStart", function(event, next, current) {
$rootScope.hashUrl = next.split('#').pop();
$rootScope.hashUrl = '#' + $rootScope.hashUrl;
console.log($rootScope.hashUrl, "URL"); //#!/addflats
$rootScope.addActiveToSidebarElement(event, next, current);
});
The function the locationChangeStart calls:
$rootScope.addActiveToSidebarElement = function(event, next, current) {
$rootScope.anchorElement = $("a[href='" + $rootScope.hashUrl + "']");
if (parentLi.hasClass('associationChildLi')) {
$rootScope.anchorElement.addClass('selectedSideBarChildActive');
$('.associationUl').slideToggle();
}
}
Both links(from navigation bar and other UI) cause the route change. How do I find which link caused the route to change?
Edit:
I will try to explain better. I have two links that open the same page. One link from a navigation bar, one from a tile.
When I open the page, I want to highlight the respective nav item. It works naturally when I use the navigation bar. When I open the page from the tile, I have to highlight the nav item.
So I am using $locationChangeStart to detect which route I am currently on and find the <li><a href='#!/addflats'>link</a></li> element in the navigation bar
which matches the current route and add a class that highlights it.
I need to find which link(navigation bar or tile) caused the route to change