Skip to content

Multiple conditions for ui-sref-active #2524

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
Hypocrite opened this issue Feb 4, 2016 · 8 comments
Closed

Multiple conditions for ui-sref-active #2524

Hypocrite opened this issue Feb 4, 2016 · 8 comments

Comments

@Hypocrite
Copy link

I am using version 0.2.17 of ui-router.

The problem is that I would like to use the possibility to have multiple rules for ui-sref-active. For example like this:
ui-sref-active="{'active': 'videos.*', 'active': 'files.*'}

Is this somehow possible? At the moment it only takes the last condition.

@BrianCerasuolo
Copy link

Having this same issue, thought maybe I was using the syntax incorrectly. It looks like it will work with multiple things, but only one of them can have the .* glob.

@fpipita
Copy link
Contributor

fpipita commented Feb 25, 2016

Hi, when used with the object literal syntax, ui-sref-active parses its argument as a plain JavaScript object: keys should be unique.

That's why only one of the conditions applies.

@ghost
Copy link

ghost commented Mar 8, 2016

ui-sref-active="{'active': 'videos.*', 'active': 'files.*'}

+1

@christopherthielen
Copy link
Contributor

I'd consider ui-sref-active="{'active': ['videos.*', 'files.*']}

@scooper91
Copy link
Contributor

Hi! Is there any update on this? It's exactly what we need for our navbar!

@mishevski8
Copy link

+1

@jcugmas
Copy link

jcugmas commented Nov 14, 2017

+1 no update for this for now, it will be useful !

@christopherthielen
Copy link
Contributor

christopherthielen commented Nov 14, 2017

I'd be happy to merge a PR (please add tests around here)

expect(template[0].className).not.toContain('activeeq');
}));
it('updates to a new href when it points to a new state', function () {
expect(angular.element(template[0]).attr('href')).toBe('#/contacts');

In the meantime,you can accomplish this with a little bit of shenanigans by nesting hidden ui-sref inside a parent ui-sref-active.

    <button ui-sref-active="active" class="btn btn-success">
      Foo is active
      <div style="display: none" ui-sref="foo.**"></div>
    </button>

See this example: http://plnkr.co/edit/URTdcIWcIgUAqa15PoH2?p=preview

christopherthielen added a commit that referenced this issue Jan 30, 2018
i.e., <div ui-sref-active="{ active: ['randomState.**', admin.roles'] }"></div>

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

No branches or pull requests

8 participants