gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 18:44:09 27 4
gpt4 key购买 nike

我对 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)

最佳答案

你忘记加载你的controller.js和services.js,这是我的猜测。将 app.js 包含在 index.html 中后尝试此操作:

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

关于javascript - 问题 - AngularJS 未捕获错误 : [$injector:modulerr],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35646030/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com