Javascript AngularJS UI路由器:将状态与组件中的$state.includes匹配

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

我有一个AngularJS(1.5.1)组件。此组件出现在我的整个应用程序中

我需要根据当前活动的URL在此组件的模板中执行一些操作

例如,当应用程序在url中显示
#/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}