【发布时间】:2015-10-07 01:23:07
【问题描述】:
我是 AngularJS 的新手。我正在尝试使用 AngularJS 使用 Wcf 数据服务。我一直在失败,因为我不确定哪里出了问题。有人可以帮我解决这个问题。谢谢。
如果这样查询,数据服务将返回 Json:
http://localhost/Wcf/DataService/Report/ReportService.svc/SystemCategories?$format=json
返回的样本 Json:
{"odata.metadata":"http://localhost/Wcf/DataService/Report/ReportService.svc/$metadata#SystemCategories","value":[
{"ID":1,"SystemName":"System-A","Description":"System A"},
{"ID":2,"SystemName":"System-B","Description":"System B"},
{"ID":3,"SystemName":"System-C","Description":"System C"}]}
代码(来自 w3school 的示例)
<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="systemCat">
<ul>
<li ng-repeat="x in categories">
{{ x.ID + ', ' + x.SystemName }}
</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('systemCat', function($scope, $http) {
$http.get("http://localhost/Wcf/DataService/Report/ReportService.svc/SystemCategories?$format=json")
.success(function (response) {$scope.categories = response.value;});
});
</script>
</body>
</html>
【问题讨论】:
标签: javascript c# json angularjs rest