相关疑难解决方法(0)

Angularjs $资源无法使用从REST API返回的数组

我正在尝试学习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/

angularjs angularjs-ng-repeat

14
推荐指数
3
解决办法
5万
查看次数

标签 统计

angularjs ×1

angularjs-ng-repeat ×1