gpt4 book ai didi

angularjs - $state.go 不能从单独的 Controller 工作

转载 作者:行者123 更新时间:2023-12-01 09:24:08 25 4
gpt4 key购买 nike

这是我的代码

$stateProvider
.state('home', {
url: "/home",
templateUrl: "views/home.tpl.html",
controller:"homeController"
})
.state('test', {
url: '/test',
templateUrl: "views/test/dashboard.tpl.html",

});

我在 index.html 页面中的模态视图是

<div class="modal-body" ng-controller="userController">
<form ng-submit="login()" >
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="text" class="form-control" id="exampleInputEmail1" ng-model="user.email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" ng-model="user.password" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Sign In</button>
</form>
</div>

我的 userController 函数是

$scope.login = function(){

console.log($scope.user);
if($scope.user.email=="xxxx" && $scope.user.password=="123456"){

$state.go("test");


}

}

Angular js 抛出错误

TypeError: undefined is not a function 在 l.$scope.login (http://localhost/yyy/scripts/controllers/userController.js:15:19) 在 ib.functionCall

状态不转移。请让我知道我错在哪里

最佳答案

感谢大家。我发现了我的错误。

以前是

myApp.controller('userController',['$scope', '$http','$rootScope','$stateParams', '$state', function ($scope,$http,$rootScope,$state, $stateParams)

改成

myApp.controller('userController',['$scope', '$http','$rootScope','$state', '$stateParams', function ($scope,$http,$rootScope,$state, $stateParams)

stateParams 和 state 的注入(inject)不按顺序进行,从而引发错误。

关于angularjs - $state.go 不能从单独的 Controller 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28470222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com