1

I am pretty new with angular 4 and i have this problem that i cant solve on my own.

My home url is localhost:4200/, and the other one is localhost:4200/wortschaz.

I want to use angular *ngIf to give an active class to a certain div based on router. So if url is localhost:4200/wortschaz then i want to set class to a div that has content for that.

Can somebody help me with this one?

George
  • 6,630
  • 2
  • 29
  • 36
dj.milojevic
  • 204
  • 1
  • 5
  • 12
  • Possible duplicate of [In Angular 2 how do you determine the active route?](https://stackoverflow.com/questions/34323480/in-angular-2-how-do-you-determine-the-active-route) – mxr7350 Oct 09 '17 at 10:43

2 Answers2

1

Use routerLinkActive

<a  routerLink="/wortschaz" routerLinkActive="activeNav">Wortschaz</a>

.activeNav {
    background-color: blue;
}
Faly
  • 13,291
  • 2
  • 19
  • 37
1

Just add <li><a routerLink='/wortschaz ' routerLinkActive='active'>wortschaz </a></li>. The routerLinkActive takes care of it

tobie
  • 187
  • 10