父级上的 Angular ui 路由器 ui-sref-active [英] Angular ui router ui-sref-active on parent

查看:22
本文介绍了父级上的 Angular ui 路由器 ui-sref-active的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个状态和许多子状态.如果我希望 ui-sref-active 在我在一个孩子身上时可以工作,我需要做这个hack":

I have one parent state and many childs states. If I want the ui-sref-active on the parent to work when I am on one of the child I need to do this "hack":

$scope.isActive = function() {  
   return $state.includes('playLotteries.Index') 
       || $state.includes('playLotteries.Group')  
       || $state.includes('playLotteries.hunter');
   }

这是非常丑陋的方式,我有很多孩子,所以这似乎不是一个好的解决方案.任何人都有针对此问题的其他解决方案?

This is very ugly way and I have many children so its not seems like good solution. Anyone have another solution for this problem?

推荐答案

您可以只检查父状态而不是检查所有子状态

You can check parent state only instead of checking all child states

$scope.isActive = function() {  
   return $state.includes('playLotteries');
}

这篇关于父级上的 Angular ui 路由器 ui-sref-active的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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