sarveshwar geetha sarveshwar geetha - 4 months ago 21
Javascript Question

Cannot read property 'go' of undefined with registerForm

I want to change my state to "login" 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.mismatch=true;

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

}
else
{
$scope.mismatch=false;
$scope.loginForm.$setValidity("valid", false);

}
}
}, true);


$scope.registerForm=function()
{
$state.go('login', {});
}

}]);

Answer

Inject $state properly

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