我正在學習角js中的路由,請幫助我以下示例。在這個例子中路由不起作用。我需要在任何服務器上運行它嗎?爲什麼角度js路由不適用於這個例子?
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.8/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.html"
})
.when("/red", {
templateUrl : "red.html"
})
.when("/green", {
templateUrl : "green.html"
})
.when("/blue", {
templateUrl : "blue.html"
});
});
</script>
<p>Click on the links to navigate to "red.htm", "green.htm", "blue.htm", or back to "main.htm"</p>
</body>
</html>
main.html中
<h2> Hello this is main.html</h2>
red.html
<h2> Hello this is red.html</h2>
green.html
<h2> Hello this is green.html</h2>
blue.html
<h2> Hello this is blue.html</h2>
你在哪裏想呢? –
你試圖在網絡服務器或瀏覽器(如HTML)? – ismailperim
我不確定角度是否加載。您的腳本標籤超出您的
或您不存在 – dbarthel