Javascript AngularJS UI路由器:将状态与组件中的$state.includes匹配
我有一个AngularJS(1.5.1)组件。此组件出现在我的整个应用程序中 我需要根据当前活动的URL在此组件的模板中执行一些操作 例如,当应用程序在url中显示Javascript AngularJS UI路由器:将状态与组件中的$state.includes匹配,javascript,angularjs,angular-ui-router,Javascript,Angularjs,Angular Ui Router,我有一个AngularJS(1.5.1)组件。此组件出现在我的整个应用程序中 我需要根据当前活动的URL在此组件的模板中执行一些操作 例如,当应用程序在url中显示#/web/foundation/color或带有web的任何其他状态时,我需要使用ng class设置一个类。因此,如果url有给定的href,我需要返回true 我试图使用ng class=“{'active':$state.includes('web')}” 与该url关联的状态为 $stateProvider.state('c
#/web/foundation/color
或带有web
的任何其他状态时,我需要使用ng class设置一个类。因此,如果url有给定的href,我需要返回true
我试图使用ng class=“{'active':$state.includes('web')}”
与该url关联的状态为
$stateProvider.state('color', {
url: '/web/foundation/color'}
});
我在web
部分中还有一些类似的设置,例如
$stateProvider.state('buttons', {
url: '/web/foundation/buttons'}
});
因此web
是URL的一部分,而不是州名
组件本身是
(function () {
'use strict';
angular.module('app').component('pbDsLeftnav', {
bindings: {},
controllerAs: 'ctrl',
templateUrl: 'core/directives/pb-ds-leftnav.component.html',
controller: function ($log, $rootScope, $state, $stateParams) {
var _this = this;
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
console.log($state.includes('web'));
}
});
})();
我试过各种版本的
'web'
,**.web.*
,但都没有用。它总是记录false
。我如何匹配州的url的一部分?知道了。但是console.log($state.href($state))代码>刚刚出错。此日志记录为null
now:console.log($state.href($state.current))代码>如果我执行console.log($state.get($state.current))代码>我得到了{name:,url:“^”,视图:null,摘要:true}
得到了。但是console.log($state.href($state))代码>刚刚出错。此日志记录为null
now:console.log($state.href($state.current))代码>如果我执行console.log($state.get($state.current))代码>我得到{name:,url:“^”,视图:null,摘要:true}