当路由处于非活动状态时,Angular2 添加类 [英] Angular2 add class when route is inactive

查看:26
本文介绍了当路由处于非活动状态时,Angular2 添加类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Angular2 有一个 routerLinkActive 指令,如果路由处于活动状态,它会向元素添加类.我想在路由非活动时添加一个类.有没有办法做到这一点?

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?

推荐答案

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

这篇关于当路由处于非活动状态时,Angular2 添加类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆