Angular2 add class when route is inactive

2019-05-06 17:48发布

问题:

Angular2 has a routerLinkActive directive which adds class to the element if the route is active. I want to add a class when route is inactive. Is there a way to do this?

回答1:

<a routerLink="/user/bob" routerLinkActive #rla="routerLinkActive" [ngClass]="rla.isActive ? 'classIfActive' : 'classIfNotActive'">
</a>