角UI路由器:我得到父视图是与如何QUOT;积极"导航到嵌套视图时? [英] Angular UI Router: How do I get parent view to be "active" when navigating to nested view?

查看:95
本文介绍了角UI路由器:我得到父视图是与如何QUOT;积极"导航到嵌套视图时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作已经实现UI路由器一个项目,它使用 UI-SREF主动=活跃到活动类添加到导航菜单项时产品的当前路由。但是,当您导航到该视图中嵌套的视图,父菜单项不再有效。请参阅以下Plunker:

I'm working on a project that has implemented the UI router and it's using ui-sref-active="active" to add the active class to the navigation menu item when that item is the current route. However, when you navigate to a nested view within that view, the parent menu item is no longer active. See the following Plunker:

http://plnkr.co/edit/2CoEdS?p=$p$pview

默认情况下(或者,如果你点击它)1号公路是积极的。当你点击显示列表,你会看到,1号线是不再有效。

By default (or if you click on it) Route 1 is "active". When you click on "Show List," you will see that Route 1 is no longer active.

编辑:

这个例子中,我的实际项目之间的唯一区别是,在我的实际项目中的导航菜单都有自己的控制器等不使用的同一范围内控制器ROUTE1。

The only difference between this example and my actual project is that the navigation menu in my actual project has its own controller and so does not use the same scope as the controller for "route1".

推荐答案

修改有关更新UI路由器0.2.13:

UI-SREF主动=活跃现在设置的活跃上课的时候​​当前的状态是UI的SREF的状态或任何儿童

ui-sref-active="active" now sets the 'active' class when the current state is the ui-sref's state or any child

UI-SREF主动-EQ =活跃的操作与UI的SREF活跃,只有设置类的确切的previous迭代状态

ui-sref-active-eq="active" behaves as the previous iterations of ui-sref-active, and only sets the class for the exact state

原来的答复:

请参阅开放的用户界面路由器的问题:
<一href=\"https://github.com/angular-ui/ui-router/issues/704\">https://github.com/angular-ui/ui-router/issues/704和 818

See open ui-router issues: https://github.com/angular-ui/ui-router/issues/704 and 818

一个通用的解决方法的人的建议是:

A general workaround people are suggesting is:

ng-class="{active:$state.includes('route1')}"

当然,$状态必须被添加到$范围。见更新普拉克: http://plnkr.co/edit/KHLDJP?p=$p$pview

这篇关于角UI路由器:我得到父视图是与如何QUOT;积极&QUOT;导航到嵌套视图时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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