如何根据当前的路由名称/控制器上设置类 [英] How to set class based on current route name/controller

查看:112
本文介绍了如何根据当前的路由名称/控制器上设置类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据尝试我的电流控制器或电流路径(URL段1)上设置的一类。

Trying to set a class based on my current controller or current route (URL Segment 1).

<body class="{{controllerName}}">

这样的情况下,我需要针对对CSS的特异性单独的页面,这使得它很容易。

That way in case I need to target separate pages for CSS specificity, it makes it easy.

推荐答案

我的解决办法是:订阅路由变化在航线范围,把控制器存在的名称:

My solution would be: subscribe to route changes at route scope and put name of the controller there:

app.run(function($rootScope) {
   $rootScope.$on('$routeChangeSuccess', function(ev,data) {   
     if (data.$route && data.$route.controller)
       $rootScope.controller = data.$route.controller;
   })
});

Plunker解决方案

这篇关于如何根据当前的路由名称/控制器上设置类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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