[英]AngularJS - TypeError: Cannot read property 'go' of undefined
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). 所以,我添加了一个按钮,在
ng-click
,我调用了函数registerForm
(你可以在下面的代码中看到)。 but when I press the button I get the following error in the browser console. 但是当我按下按钮时,我在浏览器控制台中收到以下错误。
TypeError: Cannot read property 'go' of undefined
TypeError:无法读取未定义的属性“go”
at m.$scope.registerForm (controllers.js:27)at m。$ scope.registerForm(controllers.js:27)
at fn (eval at compile (angular.js:14605), :4:227)at fn(eval at compile(angular.js:14605),:4:227)
at b (angular.js:15694)at b(angular.js:15694)
at e (angular.js:25622)在e(angular.js:25622)
at m.$eval (angular.js:17444)at m。$ eval(angular.js:17444)
at m.$apply (angular.js:17544)at m。$ apply(angular.js:17544)
at HTMLFormElement.在HTMLFormElement。 (angular.js:25627)
(angular.js:25627)
at Sf (angular.js:3488)在Sf(angular.js:3488)
at HTMLFormElement.d (angular.js:3476)在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', {});
}
}]);
正确地注入$ state
app.controller('registerController', ['$scope', '$state', function ($scope,$state) {
似乎错过了注入$ state,更新如下将有助于解决此问题。
app.controller('registerController', ['$scope','$state',function ($scope,$state)
你也需要注入$ state
app.controller('registerController', ['$scope','$state',function ($scope,$state) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.