【发布时间】:2016-03-09 04:42:04
【问题描述】:
我正在尝试学习 angularjs,但在尝试将数据绑定到从 Rest API 返回的数组时遇到了障碍。我有一个简单的 azure api 返回一组人员对象。服务网址是http://testv1.cloudapp.net/test.svc/persons。
我的控制器代码如下:
angular.module("ToDoApp", ["ngResource"]);
function TodoCtrl($scope, $resource) {
$scope.svc = $resource('http://testv1.cloudapp.net/test.svc/persons', {
callback: 'JSON_CALLBACK'
}, {
get: {
method: 'JSONP',
isArray: true
}
});
$scope.items = $scope.svc.get();
$scope.msg = "Hello World";
}
我的 html 看起来像:
<html>
<head></head>
<body>
<div ng-app="ToDoApp">
<div ng-controller="TodoCtrl">
<h1>{{msg}}</h1>
<table class="table table-striped table-condensed table-hover">
<thead>
<th>Email</th>
<th>First Name</th>
<th>Last Name</th>
</thead>
<tbody>
<tr ng-repeat="item in items">
<td>{{item.Email}}</td>
<td>{{item.FirstName}}</td>
<td>{{item.LastName}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
问题:上面html中的表格没有显示任何数据。我可以在 Firebug 中看到对 api 的调用,也可以看到来自 api 的 JSON 响应。我做错了什么导致与 REST api 的数据绑定不起作用?
PS:JSFiddle 演示此问题位于:http://jsfiddle.net/jbliss1234/FBLFK/4/
【问题讨论】:
标签: angularjs angularjs-ng-repeat