Is it possible to use ui-sref-active without having a ui-sref?

761 views Asked by At

I have this template

<div class="row">
    <div>
        <div >
            <a ui-sref-active="active" ui-sref="main.step1">
               <span>1</span>               
            </a>
            <a ui-sref-active="active" ui-sref="main.step2">
               <span>2</span>
            </a>
            <a ui-sref-active="active" ui-sref="main.step3">
               <span>3</span>                
            </a>
        </div>
    </div>
</div>

<div id="form-views" ui-view>

</div>

I have a requirement that user should not be able to navigate between theses states by clicking on urls, he should navigate between states with buttons which are in their specific templates.

I was wondering how can I use ui-sref-active without ui-sref directive?

2

There are 2 answers

0
Avnesh Shakya On

Try something like this:

<ul class="nav navbar-nav">
    <li class="icon-border">
        <a ng-class="{ active: isActiveMainBar('main.step1')}" ui-sref="main.step1">A
          </a>
    </li>
    <li class="icon-border">
        <a ng-class="{ active: isActiveMainBar('main.step2')}" ui-sref="main.step2">B
          </a>
    </li>
    <li class="icon-border">
        <a ng-class="{ active: isActiveMainBar('main.step3')}" ui-sref="main.step3">C
          </a>
    </li>
</ul>

And in controller:

$scope.isActiveMainBar = function(tab) {
    var path = $location.path();
    if (path.indexOf(tab) !== -1) {
        return true;
    } else {
        return false;
    }
};

Hope this will help you.

0
Rathma On

I came up with this function:

 function isStateActive(stateName) {
            return $state.current.name === stateName;
 }

and use it like this:

 <a  ng-class="{'active': isStateActive('main.step1')}">            <span>1</span>
  </a>