【发布时间】:2016-12-17 23:45:29
【问题描述】:
我已阅读与同一问题相关的帖子并交叉验证了我的代码,但问题仍然存在。
以下是我的 index.html 文件
<!DOCTYPE html>
<html ng-app="myModule">
<head>
<title></title>
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular-route.js"></script>
<link href="Scripts/styles.css" rel="stylesheet" />
<meta charset="utf-8" />
</head>
<body>
<table style="font-family:Arial">
<tr>
<td class="header" colspan="2" style="text-align:center">Website Header</td>
</tr>
<tr>
<td class="leftMenu">
<a href="#/home">Home</a><br/>
<a href="#/courses">Courses</a><br />
<a href="#/students">Students</a><br />
</td>
<td class="mainContent">
<div><ng-view></ng-view></div>
</td>
</tr>
</table>
</body>
</html>
script.js 文件
/// <reference path="angular-route.js" />
/// <reference path="angular.js" />
var myModule = angular.module("myModule", ["ngRoute"])
.config(function ($routeProvider) {
$routeProvider
.when("/home", {
templateUrl: "Templates/home.html",
controller: "homecontroller",
})
.when("/courses", {
templateUrl: "Templates/courses.html",
controller: "coursescontroller",
})
.when("/students", {
templateUrl: "Templates/students.html",
controller: "studentscontroller",
})
.controller("homeController", function ($scope) {
$scope.message = "HomePage";
})
.controller("coursesController", function ($scope) {
$scope.courses = ["c","c++","c#"];
})
.controller("studentsController", function ($scope) {
$scope.students = [{ name: "Chandu", id: 1, gender: "female" }, { name: "Suma", id: 2, gender: "female" }, { name: "Arin", id: 3, gender: "male" }];
})
})
我已经定义了家庭、课程和学生的 html 文件。初始加载后,当我单击任何链接时,例如。 home, /#/home 被附加到 url 但部分模板没有加载。
起初,我也没有收到任何控制台错误。但是现在我收到以下错误,即使 myModule 的名称在 script.js 和 index.html 文件中都正确使用了
Uncaught Error: [$injector:modulerr] Failed to instantiate module myModule due to:
Error: [$injector:nomod] Module 'myModule' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.5.9/$injector/nomod?p0=myModule
非常感谢任何帮助我解决问题并帮助我找出问题所在。
P.S: Index.html 位于主目录,部分模板位于主目录的模板文件夹中。我正在使用 angular.js 和 angular-route.js 的 1.5.9 版本
【问题讨论】:
标签: javascript html angularjs