0
我想加载一个“捐助者”列表为我的角应用程序。我从API获取数据,但我没有按照我想要的方式工作。我得到这个错误:
$ resourceProvider < - $资源< - DonorerCtrl
在我DonorerCtrl类我有以下代码:
angular.module("testApp").controller("DonorerCtrl",
function($scope, $http, $resource) {
console.log("Test fra donorerCtrl");
$scope.donorerResource = $resource("http://bloodadmin.cloudapp.net/api/users/:donorid"),
{id: "@donorid"}, { update: {method: "PUT"}};
$scope.donorerVisits = $scope.donorerResource.query();
$http (
{
method: "GET",
url: "http://bloodadmin.cloudapp.net/api/donors"
}).success(function(data) {
$scope.donorerVisits = data;
}).error(function() {
alert("error");
});
$scope.donorerVisits = [];
});
我尝试用这个加载它在我的HTML文件代码:
<div class="form-group col-lg-12">
<table class="table">
<thead>
<tr>
<th>Fornavn</th>
<th>Efternavn</th>
<th>Køn</th>
<th>Fødselsdag</th>
<th>Læs mere</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="visit in donorerVisits">
<td>{{visit.firstname}}</td>
<td>{{visit.lastname}}</td>
<td>{{visit.sex}}</td>
<td>{{visit.age}}</td>
<td><button class="btn btn-default">Læs mere</button></td>
</tr>
</tbody>
</table>
</div>
在我的索引HTML我加载在这些JS文件:
<!-- JS -->
<script src="libs/angular.js" type="text/javascript"></script>
<script src="libs/angular-ui-router.min.js" type="text/javascript"></script>
<script src="libs/angular-resource.js" type="text/javascript"></script>
<!-- Angular Custom -->
<script type="text/javascript">
angular.module("testApp", ['ui.router']);
</script>
<script src="js/controllers/HjemCtrl.js"></script>
<script src="js/controllers/DonorerCtrl.js"></script>
<script src="js/controllers/BlodCtrl.js"></script>
<script src="js/navigation.js"></script>
谢谢,似乎工作,但现在我有这个错误: 的index.html:1的XMLHttpRequest无法加载http://bloodadmin.cloudapp.net/api/donors。请求的资源上没有“Access-Control-Allow-Origin”标题。原因'http:// localhost:63342'因此不被允许访问。 –
您需要在服务器端启用[CORS](https://gist.github.com/mlynch/be92735ce4c547bd45f6)。 – Michael