[英]Setting <li> class to active with angular 4 based on router
I am pretty new with angular 4 and i have this problem that i cant solve on my own. 我对angular 4相当陌生,但我有无法自行解决的问题。
My home url is localhost:4200/ , and the other one is localhost:4200/wortschaz . 我的主URL是localhost:4200 / ,另一个是localhost:4200 / wortschaz 。
I want to use angular *ngIf to give an active class to a certain div based on router. 我想使用angular * ngIf为基于路由器的某个div提供活动类。 So if url is localhost:4200/wortschaz then i want to set class to a div that has content for that.
因此,如果url为localhost:4200 / wortschaz,那么我想将class设置为具有该内容的div。
Can somebody help me with this one? 有人可以帮我吗?
Use routerLinkActive 使用routerLinkActive
<a routerLink="/wortschaz" routerLinkActive="activeNav">Wortschaz</a>
.activeNav { background-color: blue; }
Just add <li><a routerLink='/wortschaz ' routerLinkActive='active'>wortschaz </a></li>
. 只需添加
<li><a routerLink='/wortschaz ' routerLinkActive='active'>wortschaz </a></li>
。 The routerLinkActive
takes care of it routerLinkActive
会照顾好它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.