I have the following code snippet for generating bootstrap nav-taps
with an embedded dropdown list:
<ul class="nav nav-tabs">
<li class="pull-right">
<a class="dropdown-toggle" data-toggle="dropdown"> More <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a [routerLink]="['/profile/settings']">Settings</a></li>
<li><a [routerLink]="['/profile/billing']">Billing</a></li>
</ul>
</li>
<li class="pull-right" [routerLinkActive]="['active']"><a [routerLink]="['/profile/feature1']">Feature1</a></li>
<li class="pull-right" [routerLinkActive]="['active']"><a [routerLink]="['/profile/feature2']">Feature2</a></li>
</ul>
This works fine for the normal tabs, but I can't figure out how to make the dropdown list active when either of the embedded links are active. I tried:
<a [routerLinkActive]="['active']" class="dropdown-toggle" data-toggle="dropdown"> More <span class="caret"></span></a>
but it doesn't seem to solve anything, anyone know how I can do this?
routerLinkActive is simply an indicator of whether this link represents the active route. @jessepinho - Tried it - [routerLinkActive]="'active'" will only work if you also have [routerLink] in the a-tag. If you had (click)="navitageTo('/route')" instead of [routerLink], and in that function, you called this.
Approach: To determine which is the active route at any moment in AngularJS this can be achieved by using $on() & $location. path() method.
The RouterLinkActive directive can also be used to set the aria-current attribute to provide an alternative distinction for active elements to visually impaired users.
I'm dumb and attempted putting the [routerLinkActive]
on the <a>
element instead of <li>
. Once I put it on the top most li
it worked like a charm!
<ul class="nav nav-tabs">
<li class="pull-right" [routerLinkActive]="['active']">
<a class="dropdown-toggle" data-toggle="dropdown"> More <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a [routerLink]="['/profile/settings']">Settings</a></li>
<li><a [routerLink]="['/profile/billing']">Billing</a></li>
</ul>
</li>
<li class="pull-right" [routerLinkActive]="['active']"><a [routerLink]="['/profile/feature1']">Feature1</a></li>
<li class="pull-right" [routerLinkActive]="['active']"><a [routerLink]="['/profile/feature2']">Feature2</a></li>
</ul>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With