Im new to AngularJS. I am trying to consume Wcf Data service with AngularJS. I keep failing as I am not sure where things are going wrong. Could someone please help me on this. Thanks.
Im AngularJS。我正在尝试使用AngularJS使用Wcf数据服务。我一直失败,因为我不知道哪里出了问题。有人能帮我一下吗?谢谢。
The data service will return Json if queried like this:
如果这样查询,数据服务将返回Json:
http://localhost/Wcf/DataService/Report/ReportService.svc/SystemCategories?$format=json
Sample Json returned:
示例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"}]}
The code (sample from w3school)
代码(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>
1 个解决方案
#1
1
This code should work, if not take a look at the javascript console and whatever errors you find there would give you some idea as to what is going wrong.
如果不查看javascript控制台,这段代码应该可以正常工作,无论您发现了什么错误,您都可以知道哪里出错了。
<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 (data) {
console.log(data);
$scope.categories = data.value;
})
.error(function (data) {
console.log('error!');
});
});
</script>
#1
1
This code should work, if not take a look at the javascript console and whatever errors you find there would give you some idea as to what is going wrong.
如果不查看javascript控制台,这段代码应该可以正常工作,无论您发现了什么错误,您都可以知道哪里出错了。
<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 (data) {
console.log(data);
$scope.categories = data.value;
})
.error(function (data) {
console.log('error!');
});
});
</script>