-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ui-sref-active not working correctly with abstract and child states #1431
Comments
The active class 'ui-sref-active' activates upon is not the abstract 'admin', but the 'admin.users' :? |
@stoykostanchev Making I feel like this really should be working the way it is, and that it's not is a bug. |
Well here's a workaround that fixes both issues for me: http://plnkr.co/edit/G5o6XkeCQfQId2XwUTXc?p=preview This creates a flat object containing the the state names and their active status (true/false) into the root scope at startup, and updates it when I needed to do this instead of using If anyone has any better ideas I'm all ears. I wish these two libraries (ui-router and ui-bootstrap) integrated with each other better. |
@timkindberg could you take a look at this since it looks like you did the PR for this? Thanks! |
+1 |
+1 I can't get any classes to work in the partial/sidebar.html |
+1 this would help alot |
+1 I run into this issue a lot and, off the top of my head, here are a couple ideas for how it could be fixed: First, you could add additional options to <a ui-sref='admin.users' ui-sref-active="{class: 'active', state: 'admin'}">Link</a> Another way that might also be generally useful would be to allow linking to abstract states if it provides a default child state. Then you could do the following: For example: // ...
.state('admin', {
url: '/admin',
abstract: true,
defaultChild: 'admin.users',
templateUrl: 'templates/adminPanel.html'
})
.state('admin.users', {
url: '',
templateUrl: 'templates/adminUsers.html'
})
// ... <a ui-sref="admin" ui-sref-active="active">Administration Panel</a> |
I just had the same problem. I like the idea to have an object intp ui-sref-active to specify the associated state :) |
@tagazok If your having the problem with a list/detail setup one way to get around it is to make your My problem is I have a settings state with multiple categories ie overview billing security teams states each with their own child states. So my above solution doesn't go very well with the above solution. |
@tagazok I have fixed this in my app by creating custom menu directive in which I have isActive func :
|
thanks @Grievoushead this is exactly what I needed ! :) |
+1 Same Problem |
+1 |
+1, also like the idea of linking to abstract state if it provides a default child |
+1 |
I have got the similar problem, what I have done: Don't use abstract within state, coz ui-sref-active support nest child state, so I use $state.go('child state') within the controller to force the parent state to go to it's child. But this will bring up the other problem, parent state's active class will never gone :( this ui-sref-active-eq won't work coz I don't give child state specific url. |
👍 +1 |
+1 for the proposed form: ui-sref-active="{class: 'active', state: 'admin'}" |
+1 |
1 similar comment
👍 |
+1 on this, but in the meantime I've worked out a somewhat hacky solution that may or may not work for your use cases.
Again, depending on what you use your states for, this may or may not work for you, but at least it lets you preserve active state natively without having to create a directive or anything else. |
+1 |
I use the following in my application:
So, if |
+1 for either specifying the state for ui-sref-active or linking to abstract states if a default child is set... or both! |
+1 Just hit this need myself in an application where I need to be "active" on an abstract parent. Reordering my hierarchy has other large implications that I can't back out of in a timely fashion right now. |
+1 @blah238 thanks for a simple solution. |
hi, i have this exect problem. i have a sidebar menu with 3 level deep. System i use states for routing. when i click Country menu item. it shows country page as expected. Country menu item highlited. no problem. then, when i click currency menu item, it show currency page but menu collapsed up to root. i analysed currency menu item via console, it has active class. i think parent elements lose their states somehow. i tried to create a plunker. i know menu doesnt collapsed at the beginning but look at the code side. it is the same code i use in my current project. http://plnkr.co/edit/rFzDMlEAvxqXJ8hDhORc?p=preview here is some screenshot: first i click Ülke (Country) item from menu. it works normally. and then i clicked Para Birimi (Currency) item it shows currency index page but menu collapsed up to root. |
+1. I'm running into issues as my parent state is abstract but I need it to be active for all its children. |
@arkin- Something similar to the example @eric-norcross posted, i.e. |
+1 |
@Grievoushead Thank you so much... You solution were awesome and simple! Thanks again |
Sorry i am new on angular, I think I'm doing something wrong. The solution from @arkin- dont works for me. Anybody can help me? |
@Giovancruz and @arkin- This directive worked perfectly for me. Thanks you so much. I spent over 8 hours trying to find a working solution. I am sorry it is not working for you @Giovancruz. |
+1 @arkin |
1 similar comment
+1 @arkin |
@Giovancruz
|
@adamalbrecht you are a saint, thanks |
I made a little change to @arkin directive
All I did was to move the logic from the controller to the link function in the directive to be able to get the ui-sref-active-if attr from a scope instead of a literal string |
It seems like people are still looking at this even though the solution is in at least the most recent version! This won't work right: <li ui-sref-active="active">
<a ui-sref="admin.users">Administration Panel</a>
</li> This will: <li ui-sref-active="{ 'active': 'admin' }">
<a ui-sref="admin.users">Administration Panel</a>
</li> |
@tgrant59 That worked. Thanks! My example:
|
@tgrant59 Thanks for the example. Notes: Angular developers are still workarounding integrated features like this one in this retarded framework. THE NEW INTEGRATED FEATURES ARE NOT DOCUMENTED AT ALL!!! Every developer must go first to the official documentation where he finds nothing useful, then he goes to stackoverflow where all solutions are outdated or bad practices, then he decides that he will either waste 2 more hours going in to the comments of a related issue and explore all pull request OR simply write a custom solution that in 100% of the cases simply overrides or workarounds core features of the framework. Thanks to the google marketing team frameworks like angular are well sold to end clients without even thinking if this framework will be a major drawback for the entire project. And that's how zillions of govnocode projects are born. PS: wasted 3 hours to find an example of this feature and to determine if this feature is actually built in to the framework... |
I solve third level navigation issue in homer theme for angular js. css for this: navigation for this:
|
This is great:
But what if you have a menu item that has two abstract items under it? current work around: |
What if you have nested abstract states as in the following routes but with a flattened menu like this:
When you are within the Users routes, both the menu items will be highlighted. To prevent this, added another class It might be helpful for someone. |
I have solved it by overriding ui-sref-active ( well, not exactly):
and then using this directive in the view:
|
@arkin- works perfectly! Thank you. |
@samuil4 Nobody on the UI Router project works for Google. We all do this in our spare time. If you don't like the situation, figure out the issue and submit a patch to the documentation. If everyone did that just once, you wouldn't need StackOverflow. |
we should have the default state for the abstract state - just like react router has index route - that will solve many problems. |
Finally I got a solution from the following issue:
|
Nice @owenXin! @christopherthielen's solution did it for me as well. |
This doesn't work in |
@owenXin Thank you very much, it worked perfect. |
@tgrant59, how to dynamically set the <li ng-repeat="menu in top_nav_bar.menu_options" class="{{ menu.class}}"
ui-sref="{{menu.sref}}" ui-sref-active="{'active': menu.sref + '.**'}">
<a class="text-capitalize">{{ menu.name }}</a>
</li> But |
http://plnkr.co/edit/c7OS1pwI5IjAAs5cEi5s?p=preview
In the example above, clicking the Administration nav element shows a view with two tabs, Users and Roles.
These correspond to the states
admin.users
andadmin.roles
, whileadmin
is an abstract state whose URL is inherited byadmin.users
. This all works fine except when setting the active class usingui-sref-active
.There are two problems in this scenario:
I would like to avoid using
$state.includes
directly sinceui-sref-active
is supposed to work on child states since 0.2.11: #927Am I doing something wrong or is this a bug?
The text was updated successfully, but these errors were encountered: