Javascript 在AngularJS中使用Wcf数据服务
我是安格拉斯的新手。我正在尝试使用AngularJS使用Wcf数据服务。我一直在失败,因为我不知道哪里出了问题。有人能帮我一下吗。谢谢 如果按以下方式查询,数据服务将返回Json:Javascript 在AngularJS中使用Wcf数据服务,javascript,c#,json,angularjs,rest,Javascript,C#,Json,Angularjs,Rest,我是安格拉斯的新手。我正在尝试使用AngularJS使用Wcf数据服务。我一直在失败,因为我不知道哪里出了问题。有人能帮我一下吗。谢谢 如果按以下方式查询,数据服务将返回Json: http://localhost/Wcf/DataService/Report/ReportService.svc/SystemCategories?$format=json 返回的Json示例: {"odata.metadata":"http://localhost/Wcf/DataService/Report/
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的示例)
-
{x.ID+','+x.SystemName}
var-app=angular.module('myApp',[]);
app.controller('systemCat',函数($scope,$http){
$http.get(“http://localhost/Wcf/DataService/Report/ReportService.svc/SystemCategories?$format=json“)
.success(函数(响应){$scope.categories=response.value;});
});
如果不查看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>
var-app=angular.module('myApp',[]);
app.controller('systemCat',函数($scope,$http){
$http.get('http://localhost/Wcf/DataService/Report/ReportService.svc/SystemCategories?$format=json')
.成功(功能(数据){
控制台日志(数据);
$scope.categories=data.value;
})
.错误(函数(数据){
console.log('error!');
});
});
Daniels code肯定会有帮助,但如果你能将$http调用提取到服务中,这将使你的angular应用程序更易于管理。请看一下这辆车,寻求帮助
<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>