2

I want to make navbar active for this i am using css but when i am going to refresh page active tab is going to remove how can i do this in angular 2?

 HTML:--


<ul class="nav navbar-nav navbar-top "
                    *ngFor="let menu of menus">
                    <li><a href="" (click)="goToPage($event)">{{menu}}
                    </a>
                    </li>
                </ul>

css:--

navigation a:FOCUS {
    box-shadow: 0 -5px 0 -4px #eee;
    color: #ffffff;
    width:30%
}

.navigation a:HOVER {
    box-shadow: 0 -5px 0 -4px #eee;
    color: #ffffff;
    width:30%
}
1
  • How do you go to a particular page? using which functionality? are you using angular router? Commented Sep 12, 2016 at 18:13

2 Answers 2

2

You can use routerLinkActive to add some css to your active route, for example:

<a routerLink="login" routerLinkActive="active-class">Login</a>
Sign up to request clarification or add additional context in comments.

1 Comment

Here in place of login i am using some dynamic property like<a>{{menu}}</a> is that a correct way to bind this routerLink="{{menu}}"?please suggest.
2
<ul class="nav navbar-nav navbar-top" *ngFor="let menu of menus">
     <li>
         <a routerLink="menu"  routerLinkActive="active">{{menu}}</a>
     </li>
</ul>

6 Comments

not getting any value on html or also in console through this:-- <a routerLink="menu" routerLinkActive="active">{{menu}}</a>
seriously? just try <li>{{menu}}</li>. do you even get any value in {{menu}}?
yes than i am getting value but when i am going to add routerLink="menu" routerLinkActive="active" it's gone.
yes error is like that:---EXCEPTION: Error in ./Menu class Menu - inline template:18:64
As of now, i'd suggest you to try with static route n check whether solution works. Eg. routerLink="/contacts"
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.