sarveshwar geetha sarveshwar geetha - 3 months ago 8x
Javascript Question

AngularJS - TypeError: Cannot read property 'go' of undefined

I want to change my state to "log in" on a button click . So , I added a button and in ng-click , I called up the function "registerForm"(which u can see in the below code). but when I press the button I get the following error in the browser console.

TypeError: Cannot read property 'go' of undefined

at m.$scope.registerForm (controllers.js:27)

at fn (eval at compile (angular.js:14605), :4:227)

at b (angular.js:15694)

at e (angular.js:25622)

at m.$eval (angular.js:17444)

at m.$apply (angular.js:17544)

at HTMLFormElement. (angular.js:25627)

at Sf (angular.js:3488)

at HTMLFormElement.d (angular.js:3476)

app.controller('registerController', ['$scope',function ($scope,$state) {

$scope.$watch('retypepassword', function()
if($scope.password === $scope.retypepassword)
$scope.loginForm.$setValidity("valid", true);

$scope.loginForm.$setValidity("valid", false);

}, true);

$state.go('login', {});



Inject $state properly

app.controller('registerController', ['$scope', '$state', function ($scope,$state) {