angular-ui-router:在控制器中使用$ state的依赖是什么?

mar*_*ike 5 angularjs angular-ui-router

这可能是一个非常简单的问题,但我在ui-router文档中找不到任何内容.我想调用$state.go()方法来更改控制器中的状态,但我得到一个"$ state not defined"错误.

为了能够使用$ state及其方法,我需要在控制器上放置什么依赖?

pac*_*age 8

它与任何其他服务相同 - 在带注释的依赖项列表或函数参数中包含它的名称:

//without annotation (inferred, not safe when minifying code)
function Controller($scope, $state) {...}

//inline annotation
module.controller('Controller', ['$scope','$state', function($scope, $state) {...}]);

//$inject property annotation
function Controller($scope, $state) {...}
Controller.$inject = ['$scope', '$state'];
Run Code Online (Sandbox Code Playgroud)