gpt4 book ai didi

regex - angularjs ui 路由器 : find level of current state

转载 作者:行者123 更新时间:2023-12-05 09:23:06 27 4
gpt4 key购买 nike

所以我使用 ui-router 和 stateparams 来嵌套子状态,并且效果很好。我现在正试图找到一种方法来指示 css 类应用程序所处的状态级别。 main.route1.section1 将是 3 个级别。

这里有一些无法工作的代码来帮助展示:

<div ng-class="{findState().currentCount}"></div>

app.run(function($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
$rootScope.findState = function() {
var currentName = $state.current.name;
var currentMatch = currentName.match(/./g);
$rootScope.currentCount = currentMatch.length;
};
});

我基本上是在寻找一种方法来获取 $state.current.name 等于 main.route1.section1 并在点处拆分它并计算如何许多在数组中并将该数字返回给 mg 级。除非您有更好的主意……比如正则表达式过滤器?

最佳答案

查看对象 $state.$current(而不是 $state.current)。特别是属性 path :它是一个数组,表示当前状态的状态层次结构。

所以你要找的是:$state.$current.path.length

关于regex - angularjs ui 路由器 : find level of current state,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24197795/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com