按照教程提供here进行AngularJS中的路由,我试图在我的本地运行相同的。
我将index.html作为
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/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>
</body>
</html>
<html>
<head></head>
<body>
This is main
</body>
</html>
<html>
<head></head>
<body>
This is red
</body>
</html>
对于green.htm和blue.htm
当我在Firefox中运行时,它按预期工作 - 输出
但是当我在Chrome中打开时,结果是
解决此CORS问题需要做些什么?
答案 0 :(得分:0)
对我而言,它在chrome上没有任何问题。以下是工作Plunker的链接: http://plnkr.co/edit/dyaY1CBvay8VXIZ2blTx?p=preview
// Code goes here
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.html"
})
.when("/green", {
templateUrl : "green.html"
})
.when("/blue", {
templateUrl : "blue.html"
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app="myApp">
<p><a href="#/">Main</a></p>
<a href="#green">Green</a>
<a href="#blue">Blue</a>
<div ng-view></div>
</body>
</html>
&#13;