简单的AngularJS路由示例不起作用
以下是AngularJS关于路由的简单示例: 我创建了两个页面: index.htm简单的AngularJS路由示例不起作用,angularjs,routes,Angularjs,Routes,以下是AngularJS关于路由的简单示例: 我创建了两个页面: index.htm <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/lib
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-route.js"></script>
<body ng-app="myApp">
<p><a href="#/!">Main</a></p>
<a href="#!red">Red</a>
<a href="#!green">Green</a>
<a href="#!blue">Blue</a>
<div ng-view></div>
<script>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.htm"
})
.when("/red", {
templateUrl : "red.htm"
})
.when("/green", {
templateUrl : "green.htm"
})
.when("/blue", {
templateUrl : "blue.htm"
});
});
</script>
<p>Click on the links to navigate to "red.htm", "green.htm", "blue.htm", or back to "main.htm"</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Red</title>
</head>
<body>
<h1>Red</h1>
</body>
</html>
var-app=angular.module(“myApp”[“ngRoute”]);
app.config(函数($routeProvider){
$routeProvider
.当(“/”时{
templateUrl:“main.htm”
})
.when(“/red”{
templateUrl:“red.htm”
})
.when(“/绿色”{
templateUrl:“green.htm”
})
.when(“/blue”{
templateUrl:“blue.htm”
});
});
单击链接导航到“red.htm”、“green.htm”、“blue.htm”或返回到“main.htm”
red.htm
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-route.js"></script>
<body ng-app="myApp">
<p><a href="#/!">Main</a></p>
<a href="#!red">Red</a>
<a href="#!green">Green</a>
<a href="#!blue">Blue</a>
<div ng-view></div>
<script>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.htm"
})
.when("/red", {
templateUrl : "red.htm"
})
.when("/green", {
templateUrl : "green.htm"
})
.when("/blue", {
templateUrl : "blue.htm"
});
});
</script>
<p>Click on the links to navigate to "red.htm", "green.htm", "blue.htm", or back to "main.htm"</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Red</title>
</head>
<body>
<h1>Red</h1>
</body>
</html>
红色
红色
发送到红色页面不起作用。您是如何运行项目的?您应该使用任何本地服务器运行此链接。检查此链接将解决您的问题您必须使用本地服务器运行您的html文件