问题 - AngularJS 未捕获错误: [$injector:模块rr]

Issue - AngularJS Uncaught Error: [$injector:modulerr]

本文关键字:injector 模块 rr 错误 AngularJS 问题      更新时间:2023-09-26

我是AngularJS的新手。因此,在我开始在我的项目中开发新应用程序之前,我尝试了示例应用程序的流程。以下是我尝试过的。

索引.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>

注册学生.html

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

应用.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'
});
}]);

服务.js

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

控制器.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)

你忘了加载你的控制器.js和服务.js这是我的猜测。在索引中包含 app.js 后,请尝试此操作.html:

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

尝试将所有 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>