Skip to content

Add ui-sref-active-includes attribute #1254

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

Closed
wants to merge 1 commit into from

Conversation

wcandillon
Copy link

fixes #1252

@christopherthielen
Copy link
Contributor

I think the whole point of ui-sref-active is that you don't have to test for an explicit state name. I'm not sure I understand the scenario you laid out in #1252, can you plunk it? If you're trying to highlight a UI element when any state under app.users is active, including app.users.default and (for example) app.users.notdefault, then that's not what ui-sref-active is for.

@dougmoscrop
Copy link

@christopherthielen but that's precisely what lots of people go and do. you have a top navbar, with a bunch of links to states (foo.index, bar.index, baz.index) and then within those there's a lot of child states of foo, bar and baz (foo.details, bar.moreinfo, baz.blahblah) but they do not descend from the index state. and we want the links to the top states to show active because you're in that 'section' of the app.

how about ui-sref-active-parent as an alternative way of expressing this? it doesn't require the explicit route reference, but it will activate if the parent state of the ui-sref is active.

so as an example, given a ui-sref to foo.bar.baz.index,

the following states would not apply active:

  • foo.*
  • foo.bar.*

but any state that contains foo.bar.baz would, e.g. foo.bar.baz.index, foo.bar.baz.detail, foo.bar.baz.detail.more.lots.really.toomuch

@nateabele
Copy link
Contributor

@eddiemonge
Copy link
Contributor

@wcandillon Can you clean up the PR please?

What about ui-sref-in-active

@christopherthielen
Copy link
Contributor

I think this bug would be irrelevant if we had proper "redirect to default substate", yes?

<a ui-sref="app" ui-sref-active="active">Go to App Default Substate</a>
$stateProvider.state('app', { redirectTo: 'app.index' })
.state('app.index', { url: '/' })
.state('app.details', { url: '/:id'})
app.run(['$rootScope', '$state', function($rootScope, $state){
      $rootScope.$on('$stateChangeStart', function(event, toState) {
        var redirect = toState.redirectTo;
        if (redirect) {
          event.preventDefault();
          if(angular.isFunction(redirect))
              redirect.call($state);
          else
              $state.go(redirect);
        }
      });
    }]);

cc: @wcandillon @dougmoscrop @eddiemonge

@dougmoscrop
Copy link

Yes, assuming that 'app' is still a valid abstract state etc

On Sat, Jun 6, 2015, 2:40 PM Chris Thielen [email protected] wrote:

I think this bug would be irrelevant if we had proper "redirect to default
substate", yes?

Go to App Default Substate

$stateProvider.state('app', { redirectTo: 'app.index' })
.state('app.index', { url: '/' })
.state('app.details', { url: '/:id'})

app.run(['$rootScope', '$state', function($rootScope, $state){
$rootScope.$on('$stateChangeStart', function(event, toState) {
var redirect = toState.redirectTo;
if (redirect) {
event.preventDefault();
if(angular.isFunction(redirect))
redirect.call($state);
else
$state.go(redirect);
}
});
}]);

cc: @wcandillon https://github.com/wcandillon @dougmoscrop
https://github.com/dougmoscrop @eddiemonge
https://github.com/eddiemonge


Reply to this email directly or view it on GitHub
#1254 (comment)
.

@gercheq
Copy link

gercheq commented Oct 6, 2016

I totally agree with @dougmoscrop I always have an abstract state for each section of my app as I'm doing some work under the hood for each section. Unfortunately I can't link to an abstract state and linking to one of the substates does not trigger .active on the navigation item.

@christopherthielen
Copy link
Contributor

For people searching and finding this issue:

  1. We now have first class support for redirects which makes it easy to implement "default substates".

  2. Although it doesn't seem to be generated in the docs properly, we have support for state name globs in ui-sref-active, e.g., ui-sref-active="{ 'active': 'admin.**' }"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in "How to: Set up a default/index child state"
6 participants