尝试使用ngRoute添加依赖项时获取依赖项注入错误

时间:2016-02-06 09:16:48

标签: angularjs ngroute

我在angularjs中创建了一个应用程序,我在其中添加依赖项作为ngRoute进行路由并创建一个服务以进行休息调用。当我试图用ngRoute注入依赖时,我得到的误差低于。

angular.min.js:6 Uncaught Error: [$injector:modulerr]     http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=loginDo&p1=Error%3A…tp%3A%2F%2Flocalhost%3A8081%2FWebServices%2Fjs%2Fangular.min.js%3A19%3A463)

loginService.js

var loginService=angular.module('loginService',['ngResource']);

loginService.factory('loginFactory',['$resource',function($resource){

    return $resource('http://localhost:8081/WebServices/rest/Authentication?  userName=:username'+'&password=:password');
}]);

loginCtrl.js

var logintest=angular.module('loginDo',['ngRoute','loginService']);

logintest.config(['$routeProvider', function($routeProvider){
 $routeProvider
    .when('/register' , { 
        templateUrl:'registration_ang.html',
        controller: 'loginCtrl'
    })
    .when('/login' , { 
        templateUrl:'login.html',
        controller: 'loginCtrl'
    })

    .otherwise({
        redirectTo : '/login'
    })
    ;

}]);


logintest.controller('loginCtrl',['$scope',function($scope){

$scope.login=function(){

    console.log("inside loginCtrl : login function");
    var username=$scope.username;
    var password=$scope.password;

          /*loginFactory.query({'username':username,'password':password},function(data){
        console.log('result:'+data);
        alert('result:'+data);
    })*/

};
}

]
);

的login.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>registration_ang.html</title>

    <script type="text/javascript" src= "/WebServices/js/angular.min.js"></script>
    <script type="text/javascript" src= "/WebServices/js/angular-resource.min.js"></script>
    <script type="text/javascript" src= "/WebServices/js/angular-route.min.js"></script>
    <script type="text/javascript" src= "/WebServices/js/friendsCtrl.js"></script>
    <script type="text/javascript" src= "/WebServices/js/friendsService.js"></script>
    <script type="text/javascript" src= "/WebServices/js/loginCtrl.js"></script>
    <link rel="stylesheet" type="text/css" href="./css/bootstrap.min.css"> 


</head>
<body >

<div ng-app="loginDo">  

    <div class="col-md-4 ">
    <h2>Login</h2>
    <form name="form"  role="form" ng-submit="login()">

        <div class="form-group"  >
            <label for="username">Username</label>
            <input type="text" name="username" id="username" class="form-control" ng-model="username" required />
            <span ng-show="form.username.$dirty && form.username.$error.required" class="help-block">Username is required</span>
        </div>

       <div class="form-group" >
            <label for="password">Password</label>
            <input type="password" name="password" id="password" class="form-control" ng-model="password" required />
            <span ng-show="form.password.$dirty && form.password.$error.required" class="help-block">Password is required</span>
        </div>

        <div class="form-actions">
            <button type="submit"  class="btn btn-primary">Login</button>
        </div>




    </form>
</div>

</div>      
</body>
</html>

任何人都可以帮助我,我在这里做错了什么。

谢谢

1 个答案:

答案 0 :(得分:0)

您忘记包含loginService.js文件。应该是:

<script src="friendsCtrl.js"></script>
<script src="friendsService.js"></script>
<script src="loginCtrl.js"></script>
<script src="loginService.js"></script>