/// <reference path="Scripts/angular.js" />
var myApp = angular.module("myModule", ["ngRoute"])
.config(function ($routeProvider) {
$routeProvider
.when("/home", {
templateUrl: "homeHTML.html",
controller: "homeController"
})
.when("/courses", {
templateUrl: "coursesHTML.html",
controller: "coursesController"
})
.when("/student", {
templateUrl: "studentHTML.html",
controller: "studentController"
})
})
.controller("homeController", function ($scope) {
$scope.message = "Home";
})
.controller("coursesController", function ($scope) {
$scope.message = "Courses";
})
.controller("studentController", function ($scope) {
$scope.message = "Student";
});
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="myModule">
<head>
<script src="Scripts/angular.min.js"></script>
<script src="Scripts/angular-route.min.js"></script>
<script src="Script.js"></script>
<title></title>
</head>
<body>
<table>
<tr>
<td colspan="2" style="width:600px; height:100px; background-color:#b4b4b4; text-align:center">
This is the header area
</td>
</tr>
<tr>
<td style="width:200px; height:400px; background-color:#ff0000">
<ul>
<li><a href="#/home">Home</a></li>
<li><a href="#/courses">Courses</a></li>
<li><a href="#/student">Student</a></li>
</ul>
</td>
<td style="width:400px; height:400px; background-color:#ff6a00">
<ng-view></ng-view>
</td>
</tr>
<tr>
<td colspan="2" style="width:500px; height:100px; background-color:#b4b4b4; text-align:center">
This is a Footer Area
</td>
</tr>
</table>
</body>
</html>
homeHTML,studentHTML,coursesHTML都是下同。
<h1>{{message}}</h1>
<div>
<p>Hi this is home partial view</p>
</div>
我發現這個錯誤的片段部分
Error:{
"message": "Uncaught ReferenceError: angular is not defined",
"filename": "http://stacksnippets.net/js",
"lineno": 51,
"colno": 13
}
這裏發生了什麼事是我得到的視圖,如圖所示的代碼片段,其中在瀏覽器中沒有任何錯誤,還當我點擊鏈接家庭,課程,學生沒有出現。 請指出這裏出了什麼問題。
你不應該放在頭部的腳本,而是應該把腳本標籤體結束之前,並確保anular.min.js加載 – user93
沒有不產生任何問題。你可以將腳本保留在html中的任何地方,但是它最好保存在角度JS應用程序中的頭部或boday標籤的開頭。 –