1

How can I give an child element of an ui-sref anchor the ui-sref-active class?

I tried to do this in my menu on all anchors:

<a ui-sref="some.route">
    <h2 ui-sref-active="selected">CLICK HERE</h2>
</a>

but it doesn't work. I'm new to Angular, so could someone maybe tell me what I'm doing wrong?

1 Answer 1

1

There is a working plunker

As stated in the doc:

ui-sref-active

...
ui-sref-active can live on the same element as ui-sref or on a parent element. The first ui-sref-active found at the same level or above the ui-sref will be used.
...

we need the parent (or current) element. So this will work:

<li ui-sref-active="selected">
    <a ui-sref="home">home</a></li>
<li ui-sref-active="selected">
    <a ui-sref="parent">parent</a></li>
<li  ui-sref-active="selected">
    <a ui-sref="parent.child">parent.child</a></li>

Check it in action here

Sign up to request clarification or add additional context in comments.

1 Comment

Great to see that, Steve! Enjoy mighty UI-Router ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.