如何检查ui-router中的当前状态是否为抽象状态的子节点

时间:2020-12-30 19:37:41

I have an abstract state "settings" with a set of children defined using strings, like "settings.personal", "settings.business" and so on. I need to check in a higher level shared controller if current state is a child of abstract "settings" state.

我有一个抽象状态“设置”,其中包含一组使用字符串定义的子项,如“settings.personal”,“settings.business”等。如果当前状态是抽象“设置”状态的子节点,我需要检查更高级别的共享控制器。

I can't figure out how to check for this? I tried to use $state.is hoping it's smart enough to detect this but it seems it's not.

我无法弄清楚如何检查这个?我试图使用$ state.is希望它足够智能来检测这个,但似乎不是。

$state.is("settings") # => false
$state.is("settings.personal") # => true

So, any other idea?

那么,还有其他想法吗?

1 个解决方案

#1


8  

Ok I now see that there's also $state.includes method which does exactly what I wanted.

好吧,我现在看到还有$ state.includes方法,它完全符合我的要求。

I'll leave this question for community to judge if it's worth keeping or should it be deleted.

我会留下这个问题供社区判断是否值得保留或是否应删除。

#1


8  

Ok I now see that there's also $state.includes method which does exactly what I wanted.

好吧,我现在看到还有$ state.includes方法,它完全符合我的要求。

I'll leave this question for community to judge if it's worth keeping or should it be deleted.

我会留下这个问题供社区判断是否值得保留或是否应删除。