AngularJS錯誤:只支持協議方案的跨源請求:http、data、chrom-擴展名、https。我有一個非常簡單的角js應用程序的三個文件。index.html<!DOCTYPE html><html ng-app="gemStore">
<head>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js'></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body ng-controller="StoreController as store">
<div class="list-group-item" ng-repeat="product in store.products">
<h3>{{product.name}} <em class="pull-right">{{product.price | currency}}</em></h3>
</div>
<product-color></product-color>
</body></html>產品-彩色.html<div class="list-group-item">
<h3>Hello <em class="pull-right">Brother</em></h3></div>app.js(function() {
var app = angular.module('gemStore', []);
app.controller('StoreController', function($http){
this.products = gem;
}
);
app.directive('productColor', function() {
return {
restrict: 'E', //Element Directive
templateUrl: 'product-color.html'
};
}
);
var gem = [
{
name: "Shirt",
price: 23.11,
color: "Blue"
},
{
name: "Jeans",
price: 5.09,
color: "Red"
}
];})();當我使用名為ProductColor的自定義指令輸入了Product-chro.html的包含時,我就開始得到這個錯誤:XMLHttpRequest cannot load file:///C:/product-color.html. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource.angular.js:11594 Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/product-color.html'.可能出什么問題了?這是產品的路徑問題嗎?我的三個文件都在同一個根文件夾中。C:/user/project
3 回答

拉風的咖菲貓
TA貢獻1995條經驗 獲得超2個贊
非常簡單的修正
轉到應用程序目錄 啟動SimpleHTTPServer
$ cd yourAngularApp~/yourAngularApp $ python -m SimpleHTTPServer

繁花如伊
TA貢獻2012條經驗 獲得超12個贊
ThinkPad-T430:~$ google-chrome --allow-file-access-from-filesThinkPad-T430:~$ google-chrome --allow-file-access-from-files fileName.htmlThinkPad-T430:~$ chromium-browser --allow-file-access-from-filesThinkPad-T430:~$ chromium-browser --allow-file-access-from-files fileName.html
cmd
- 3 回答
- 0 關注
- 653 瀏覽
添加回答
舉報
0/150
提交
取消