Reputation: 1333
This may be a really simple question but I can't find anything in the ui-router docs. I want to call the $state.go()
method to change a state in a controller, but I get a "$state not defined" error.
What is the dependency I need to put on my controller in order to be able to use $state and its methods?
Upvotes: 5
Views: 7711
Reputation: 4801
It is the same as with any other service - include it's name in annotated dependency list or function arguments:
//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'];
Upvotes: 8