ElenaDBA ElenaDBA - 28 days ago 8
AngularJS Question

Getting `state not defined` error when it is defined

In my angular application I want to go to another page on a click of a button. For that I use GoNext function. Below is my code that gives me

state is not defined
error. Can anyone tell me what is going on?

(function () {
angular.module("MyApp").controller("MainCtrl", ["$scope", "$state", "$http", MainCtrlFunction]);
function MainCtrlFunction($scope, $state, $http) {

....



$scope.GoNext = function () {
state.go("screen2");
}


}

})();


I do have a corresponding entry in my config file.

Answer

You've miss typed the service $state's name. It's just a confusion because you have two things named state on your code: the argument $state which is a service and the state of your aplication router; Anyways, it should look like:

$state.go("screen2");

Instead of:

state.go("screen2");
Comments