Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular-ui-router: what is the dependency for using $state in a controller?

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?

like image 791
mariachimike Avatar asked Oct 24 '13 04:10

mariachimike


1 Answers

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'];
like image 88
package Avatar answered Oct 14 '22 06:10

package