问题 - AngularJS未捕获错误:[$ injector:modulerr]

问题描述:

AngularJS是全新的。所以在我开始在我的项目中开发一个新应用之前,我正在尝试应用示例流程。以下是我所尝试过的。

的index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html ng-app="app"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Insert title here</title> 
<script src="lib/angular.min.js"></script> 
<script src="lib/angular-route.js"></script> 
<script type="text/javascript" src = "js/app.js"></script> 
</head> 
<body> 
    <h1>Student Registration!</h1> 
    <div ng-view></div> 
</body> 
</html> 

registerStudent.html

<table> 
<tr> 
    <td><input type="button" value="Save" ng-click="save()"></td> 
    <td>{{message}}</td> 
</tr> 
</table> 

app.js

var app = angular.module("app", ['ngRoute', 'app.services', 'app.controllers']); 

/**routing*/ 
app.config(['$routeProvider', function($routeProvider){ 

$routeProvider.when('/editStudent', { 
    templateUrl:'html/editStudent.html', 
    controller:'studentReg' 
}); 

$routeProvider.when('/viewStudent', { 
    templateUrl:'html/viewStudent.html', 
    controller:'studentReg' 
}); 

$routeProvider.when('/registerStudent', { 
    templateUrl:'html/registerStudent.html', 
    controller:'studentReg' 
}); 

$routeProvider.otherwise({ 
    redirectTo: '/registerStudent' 
}); 
}]); 

services.js

var app = angular.module('app.services', []); 
app.service('restService', function(){ 
    this.save=function(){ 
    return 'saved'; 
    }; 
}); 

controller.js

var app = angular.module('app.controllers', []); 
app.controller('studentReg', function($scope, restService){ 
$scope.result=restService.save(); 
    $scope.save=function(){ 
     console.log($scope.result); 
     $scope.message=$scope.result; 
    }; 
}); 

当我试图运行应用程序,我得到了下面的错误。

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.0-rc.1/$injector/modulerr?p0=app&p1=Error%3…2Flocalhost%3A8080%2FEnhancedStudentform%2Flib%2Fangular.min.js%3A20%3A421) 
+0

什么是完整错误? –

+0

我在问题末尾编辑了完整的错误。 – Kaushi

+0

EnhancedStudentform是应用程序的名称。 http:// localhost:8080/EnhancedStudentform /是我用来调用应用程序的URL。 – Kaushi

你忘了加载您controller.js和services.js,这是我的猜测。将index.html中的app.js加入后请尝试以下操作:

<script type="text/javascript" src = "js/controller.js"></script> 
<script type="text/javascript" src = "js/services.js"></script> 
+0

我仍然得到相同的错误.....任何其他方式来解决这个问题? – Kaushi

+0

这应该真的解决它,尝试清除缓存并重新启动您的网络服务器。你是否得到完全相同的错误?否则请更新您的答案,以便我们可以看到新的错误。 – Noshii

+0

嘿@Noshii雅其清除缓存并重新启动服务器后修复它。 – Kaushi

尝试包括所有的JS文件在你的HTML指标,如:

<script type="text/javascript" src = "js/app.js"></script> 
<script type="text/javascript" src = "js/controller.js"></script> 
<script type="text/javascript" src = "js/services.js"></script>