Angularjs Angular-对象$state,其属性current返回的值与$state.current不同

Angularjs Angular-对象$state,其属性current返回的值与$state.current不同,angularjs,Angularjs,我正在调试angular应用程序,希望获得当前的$state 当我console.log($state)并在这里查看对象时,参数“current”是什么样子的 current: Object controller:"projectsController" controllerAs:"vm" name:"app.project" templateUrl:"app/controllers/project/template.html" url:"/Project/{id}" 但是

我正在调试angular应用程序,希望获得当前的$state

当我
console.log($state)
并在这里查看对象时,参数“current”是什么样子的

current:
  Object controller:"projectsController"
  controllerAs:"vm"
  name:"app.project"
  templateUrl:"app/controllers/project/template.html"
  url:"/Project/{id}"
但是,当I
console.log($state.current)

下面是它的样子:

abstract:true
name:""
url:"^"
views:null
为什么它们不同?我不明白

我的代码很简单

console.log($state.current)
console.log($state)

您需要等待$state.current解析。试试这个:

$timeout(函数(){console.log($state.current,'shouldconsole now');})

这里有更好的处理状态更改事件的方法:

$scope.$on(“$stateChangeSuccess”,函数(事件、toState、toParams、fromState、fromParams){
//toState==$state.current

});

您需要等待$state.current解析。试试这个:

$timeout(函数(){console.log($state.current,'shouldconsole now');})

这里有更好的处理状态更改事件的方法:

$scope.$on(“$stateChangeSuccess”,函数(事件、toState、toParams、fromState、fromParams){
//toState==$state.current
});