cha-cha
cha-cha

Reputation: 338

Angular2 add class when route is inactive

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?

Upvotes: 10

Views: 3911

Answers (1)

Scipion
Scipion

Reputation: 11888

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

Upvotes: 23

Related Questions