I'm working on a project that has implemented the UI router and it's using ui-sref-active="active"
to add the active class to the navigation menu item when that item is the current route. However, when you navigate to a nested view within that view, the parent menu item is no longer active. See the following Plunker:
http://plnkr.co/edit/2CoEdS?p=preview
By default (or if you click on it) Route 1 is "active". When you click on "Show List," you will see that Route 1 is no longer active.
Edit:
The only difference between this example and my actual project is that the navigation menu in my actual project has its own controller and so does not use the same scope as the controller for "route1".
I hope this is what you have been looking for.Place the parent url in the list class ,now whenever you navigate to child class parent class will be active
Step 1: Add a Controller for your nav bar orin your existing controller where nav bar is included add the following
Step2: In your nav bar
Thats it.
Now they have updated and the new way to do that is
Below is the state file
We already have a solution without any "hack" HERE
That's the way to do:
HTML >
Our router config will be like this >
My solution was to set:
The state was already previously added to the controller's scope:
I have come here 2 years later the question was asked but
angular-ui-router
has much proficient approach in solving this issue. It worked for nested states too.When app navigates to
home
state, this is how resulting HTML will appear :Complete documentation.
You do not need to do any thing in the controllers. Here is my example code:
In route configuration: