$ state.go不是从单独的控制器工作

Ala*_*ene 3 angularjs angular-ui-router

这是我的代码

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

});
Run Code Online (Sandbox Code Playgroud)

我在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>
Run Code Online (Sandbox Code Playgroud)

我的userController函数是

$scope.login = function(){

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

         $state.go("test");


     }

 }
Run Code Online (Sandbox Code Playgroud)

Angular js正在抛出错误

TypeError:undefined不是l. $ scope.login(http://localhost/yyy/scripts/controllers/userController.js:15:19)的函数,位于ib.functionCall

国家没有转移.请让我知道我错在哪里

Ala*_*ene 7

谢谢大家.我发现了自己的错误.

早些时候是

myApp.controller('userController',['$scope', '$http','$rootScope','$stateParams', '$state', function ($scope,$http,$rootScope,$state, $stateParams)
Run Code Online (Sandbox Code Playgroud)

并改为

myApp.controller('userController',['$scope', '$http','$rootScope','$state', '$stateParams', function ($scope,$http,$rootScope,$state, $stateParams)
Run Code Online (Sandbox Code Playgroud)

stateParams和state的注入不是有序的,并且引发了错误.