Angularjs $state.onEnter()中注入$state时的当前不同值

Angularjs $state.onEnter()中注入$state时的当前不同值,angularjs,angular-ui-router,Angularjs,Angular Ui Router,这是我的代码: angular.module("LearnRouter", ["ui.router"]) .config(['$stateProvider', function(stateProvider) { stateProvider.state('state1', { controller: function($scope, $state) { $scope.state3 = function() { $state.go('s

这是我的代码:

angular.module("LearnRouter", ["ui.router"])

.config(['$stateProvider',
  function(stateProvider) {

    stateProvider.state('state1', {
      controller: function($scope, $state) {
        $scope.state3 = function() {
          $state.go('state3');
        }
      },
      template: "<h1><i>Template1</i><div ui-view><button type='button' ng-click=state3()>State 3</button></div></h1>",
      availableOptions:["option1","option2","option3"]
    });

    stateProvider.state('state2', {
      template: "<h1>Template2</h1>"
    });

    stateProvider.state('state3', {
      parent: "state1",
      template: "<h1>Template3<div>Names: <span ng-bind=names></span</div></h1>",
      controller: function($scope, $state) {
        $scope.names=$state.current.availableOptions;
      },
      onEnter:function($state){
        console.log($state)
      }
    });
  }
])


.service('namesRepo', function() {

  this.fetch = function() {
    return ['name1', 'name2', 'name3'];
  }

})

.controller("IndexController", ["$scope", "$state",
  function($scope, $state) {

    $scope.state1 = function() {
      $state.go('state1');
    }

    $scope.state2 = function() {
      $state.go('state2');
    }
  }
]);
angular.module(“LearnRouter”[“ui.router”])
.config([“$stateProvider”,
函数(状态提供程序){
stateProvider.state('state1'{
控制器:函数($scope,$state){
$scope.state3=函数(){
$state.go('state3');
}
},
模板:“模板1状态3”,
可用选项:[“选项1”、“选项2”、“选项3”]
});
stateProvider.state('state2'{
模板:“模板2”
});
stateProvider.state('state3'{
父项:“state1”,

template:“Template3Names:
OneNet
onExit
回调在转换仍在进行时被调用。
$state。当前的
在转换完全完成之前不会被更新。一旦转换完成,
$state.current
被设置为“to”调用state$stateChangeSuccess,并调用控制器


因此,
$state.current
包含“from”在
onEnter
onExit

期间声明当我记录整个$state对象时,current的值实际上是state3,而当我记录$state.current时,它是state1。因为chrome在扩展$state.current时在控制台中懒散地评估它。转换完成后,您将对它进行扩展。在console.log($state)之后立即放置断点,然后检查$state.current.name的值,它将是'state1'好的,今天我将测试您的建议。感谢您,状态不会继承任意属性。但是,状态声明的
data
属性是原型继承的。请参阅文档,特别是'data'属性