我正在尝试学习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";
}
Run Code Online (Sandbox Code Playgroud)
我的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>
Run Code Online (Sandbox Code Playgroud)
问题:上面的html表格没有显示任何数据.我可以在Firebug中看到对api的调用,也可以看到来自api的JSON响应.我做错了什么导致数据绑定到REST api不起作用?
PS:JSFiddle演示此问题的地址是:http://jsfiddle.net/jbliss1234/FBLFK/4/