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', {});
}
}]);
正确地注入$ 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) {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.