添加一个类基于当前状态下的用户界面视图 [英] add a class to the ui-view based on the current state

查看:128
本文介绍了添加一个类基于当前状态下的用户界面视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个AngularJS(1.2.7)项目,使用的UI路由器(0.2.8),我想申请的当前状态为一类到UI视图元素,因为这可以让我申请特定状态的动画,例如:做一个过渡,从登录要开始做转移B从开始去设置。

In a AngularJS (1.2.7) project, using UI Router (0.2.8), I want to apply the current state as a class to the ui-view element, because that would allow me to apply animations for specific states, e.g. do transition A going from login to start and do transition B going from start to settings.

目前,我对$ rootScope的$状态对象(如提到这里,这让我用纳克级=$ state.current.name在身体上添加一个基于状态的类。但是,如果我补充一点,到UI视图元素,如:

At the moment I have the $state object on the $rootScope (as mentioned here, which allows me to add a state-based class on the body using ng-class="$state.current.name". However, if I add that to the ui-view element, e.g.

<div ui-view ng-class="$state.current.name"></div>

那么类是一步背后的实际状态。因此,从登陆到开始走出去的时候,班级将登录,而不是启动。

Then the class is one step behind the actual state. So when going from "login" to "start", the class will be "login" instead of "start".

推荐答案

我觉得这是一个错误,你可以阅读更多关于这里的问题:

I think this is a bug, you can read more about the issue here:

<一个href=\"https://github.com/angular-ui/ui-router/issues/866\">https://github.com/angular-ui/ui-router/issues/866

直到它是固定的,我建议这样的解决方法:

Until it is fixed I suggest such a workaround:

<div ng-class="$state.current.name"><div ui-view></div></div>

这篇关于添加一个类基于当前状态下的用户界面视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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