ui-router icon indicating copy to clipboard operation
ui-router copied to clipboard

Multiple conditions for ui-sref-active

Open Hypocrite opened this issue 10 years ago • 8 comments

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.

Hypocrite avatar Feb 04 '16 11:02 Hypocrite

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.

BrianCerasuolo avatar Feb 24 '16 20:02 BrianCerasuolo

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.

fpipita avatar Feb 25 '16 08:02 fpipita

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

+1

ghost avatar Mar 08 '16 08:03 ghost

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

christopherthielen avatar Mar 08 '16 20:03 christopherthielen

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

scooper91 avatar Jul 19 '17 12:07 scooper91

+1

mishevski8 avatar Jul 21 '17 15:07 mishevski8

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

jcugmas avatar Nov 14 '17 09:11 jcugmas

I'd be happy to merge a PR (please add tests around here) https://github.com/angular-ui/ui-router/blob/5b54cbf89db3a908fae55485d2796ce79f4dea2e/test/stateDirectivesSpec.js#L410-L415

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 avatar Nov 14 '17 17:11 christopherthielen