Angularjs错误:未捕获错误:[$ injector:modulerr]

时间:2016-07-01 11:21:12

标签: angularjs express

我正在制作一个AngularJS应用程序,我在其中使用Express作为后端。问题是,每当我运行我的应用程序时

angular.js:36Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.0-beta.14/$injector/modulerr?p0=starter&p1=….com%2Fajax%2Flibs%2Fangularjs%2F1.3.0-beta.14%2Fangular.min.js%3A18%3A139)

在浏览器控制台中出现以上错误。我尝试了很多解决方案,但没有一个解决方案。

我的index.html是

 <!DOCTYPE html>
<html ng-app="starter">
  <head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title>AngularJS Routing example</title>
    <script src="hhtp://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.14/angular.min.js"></script>
    <script src="http://localhost/try/www/js/ng-cordova.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js"></script>
    </head>

  <body>
    <div class="container">
        <div class="row">
        <div class="col-md-3">
            <ul class="nav">

            </ul>
        </div>
        <div class="col-md-9">
            <div ng-view></div>
        </div>
        </div>
    </div>
    <script src="http://localhost/try/www/js/app.js"></script>
    <script src="http://localhost/try/www/js/master_serverquery.js"></script>
    <script src="http://localhost/try/www/js/employeeCtrl.js"></script>
  </body>
</html>

我的login.html是

<!DOCTYPE html>
<html  >

<head>
    <meta charset="utf-8">
    <title>Daily UI - Day 1 Sign In</title>
    <link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700|Lato:400,100,300,700,900' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="http://localhost/try/www/css/animate.css">
    <link rel="stylesheet" href="http://localhost/try/www/css/style.css">
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.14/angular.min.js"></s‌​cript>
    <script src="http://localhost/try/www/js/ng-cordova.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js"></script>

</head>

<body ng-app="starter" >
    <div ng-controller="loginCtrl">
        <div class="top">
            <h1 id="title" class="hidden"><span id="logo"></span></h1>
        </div>
        <div class="login-box animated fadeInUp">
            <div class="box-header">
                <h2>Log In</h2>
            </div>
                <form method="POST">
                    <label for="username">Username</label>
                    <br/>
                    <input type="text" name = "login" ng-model="loginId">
                    <br/>
                    <label for="password">Password</label>
                    <br/>
                    <input type="password" name = "password" ng-model = "loginPassword" >
                    <br/>
                    <button type="submit" ng-click = "loginFunc()">Sign In</button>
                    <br/>
                    <a href="#home"> Add New Order </a>
               </form>
            <a href="#"><p class="small">Forgot your password?</p></a>
        </div>
    </div>

<script src="http://localhost/try/www/js/app.js"></script>
<script src="http://localhost/try/www/js/master_serverquery.js"></script>

</body>
</html>

我的app.js是

var app = angular.module('starter', ['ngRoute','ngCordova']);
console.log("error")
app.run(function( $cordovaSQLite) {
    db = window.openDatabase("marketplace.db", '1', 'my', 1024 * 1024 * 100); 
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS user_master_vendor (server_db_column_id integer, name text)");
    console.log("browser");
});
 app.config(['$routeProvider',
   function($routeProvider) {
     $routeProvider.
       when('/login', {
        templateUrl: 'template/login.html',
        controller: 'loginCtrl'
    }).
       otherwise({
        redirectTo: '/login'
       });
 }]);

app.run(function($rootScope){
     $rootScope.project_url = 'http://127.0.0.1:8081';
})

app.controller('loginCtrl',function($scope, $http, $rootScope ,$location, $cordovaSQLite){
    $scope.loginFunc = function($scope){
        var loginPassword = $scope.loginPassword;
        var loginId = $scope.loginId;
        console.log("   loginCtrl");
        $scope.user = {
            loginId : loginId,
            loginPassword : loginPassword
        }
        alert($scope.user.loginId);
        var loginUrl = $rootScope.project_url + '/login_post';
            $http({
                    method : 'POST',
                    url : loginUrl,
                    headers: {
                                'Content-Type': undefined
                            },
                    params: {
                                loginId : loginId,
                                loginPassword : loginPassword
                            },
                    dataType: 'json',
                    processData : false
            }).then(function successCallback(response) {
                            console.log(response.data.result[0].Emp_Id);
                            console.log(response.data.result[0].Emp_Password);
                            console.log("successCallback called");

                            var server_db_column_id =  response.data.result[0].Id;
                            var user_name = response.data.result[0].Name;
                            $cordovaSQLite.execute(db, 'INSERT INTO user_master_vendor (server_db_column_id, name) VALUES (?, ?)',
                                                                       [server_db_column_id, user_name])
                                  .then(function(result) {
                                      console.log("Data Saved Successfully in user_master at INSERT ID -> " + result.insertId);
                                      console.log("Data user_empId-> " + user_empId + ", user_empPassword->" +user_empPassword);
                                    },
                                    function(error) {
                                      $scope.showp = "Data could not be saved in user_master_vendor Error -> " + error.message;
                                      console.log(error);
                                    });

                }, function errorCallback(response) {
                            alert("failure: "+response);
                });
    }
});

1 个答案:

答案 0 :(得分:0)

非常感谢帮助我。我找到了问题的灵魂,需要使用npm下载angular-route模块。以下链接帮助了我。 https://docs.angularjs.org/api/ngRoute 我遵循了所有步骤,并且能够解决问题。