Search code examples
angular-ui

How to detect current state within directive


I'm using AngularUI's routing and I'd like to do a ng-class="{active: current.state}" but I'm unsure how to exactly detect the current state in a directive like this.


Solution

  • Also you can use ui-sref-active directive:

    <ul>
      <li ui-sref-active="active" class="item">
        <a href ui-sref="app.user({user: 'bilbobaggins'})">@bilbobaggins</a>
      </li>
      <!-- ... -->
    </ul>
    

    Or filters: "stateName" | isState & "stateName" | includedByState