【发布时间】:2014-08-31 08:57:57
【问题描述】:
这是我的“app.js”的代码:
var app = angular.module('WebUI',[]);
app.config(function($httpProvider){
delete $httpProvider.defaults.headers.common['X-Requested-With'];
});
app.config(function($locationProvider){
$locationProvider.html5Mode(true);
});
这是我的控制器的代码:
var Controller = function ($scope,$http)
{
$scope.thingsList=[];
$http({method: 'GET', url: 'http://192.168.1.4/search'}).success(function(data)
{
results=data.results;
angular.forEach(results,function(result)
{
$scope.thingsList.push(result.split('/')[1]);
});
}).error(function(data){});
}
这是我的 HTML 页面的代码:
<!DOCTYPE html>
<head>
<title>All</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<script src="controller.js" type="text/javascript"></script>
</head>
<body>
<a href="home.html">HOME</a>
<div id='content' ng-app='WebUI' ng-controller='Controller'>
<li ng-repeat="thing in thingsList">
<a href="home.html">{{thing}}</a>
</li>
</div>
</body>
</html>
这里的重点是我正在使用 ng-repeat 和从我的 controller.js 获得的列表生成链接。但是会发生什么:当我单击“HOME”时,它会重定向到主页,当我单击任何“事物”(即生成的链接)时,它会引发错误:
Error: Failed to execute 'pushState' on 'History': A history state object with URL 'file:///home/abc/home.html' cannot be created in a document with origin 'null'.
我尝试在线搜索此错误,但找不到任何有用的信息。所以如果有人知道问题出在哪里,请帮助:)
【问题讨论】:
-
你能创建一个 plunker 吗?
-
应用程序很大,所以很遗憾不能。实际上这个问题只有一页......在上一页上,它工作正常:(
-
这是您遇到问题的原因stackoverflow.com/a/20079760/1690339
-
是的,但在我的情况下不明白:(
标签: javascript angularjs