mariachimike
mariachimike

Reputation: 1333

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?

Upvotes: 5

Views: 7711

Answers (1)

package
package

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

Related Questions