【发布时间】:2014-04-09 21:59:55
【问题描述】:
我有一个用 Java 编写的 REST 服务,它以 JSON 格式返回一组数据,如下所示:
[{"key":"London","value":"51.30"}]
现在我正在尝试使用 AJS 文档编写 AngularJS REST 客户端。到目前为止,我已经能够调用 REST 服务(我可以从服务器日志中看到),但 HTML 页面中没有打印任何内容。 这是我的代码:
<!doctype html>
<html >
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular-resource.js"></script>
<script language="javascript">
angular.module('myApp',['ngResource']);
function Ctrl($scope,$resource) {
var Geonames = $resource(
'http://localhost:8080/rest-application/rest/json', {
}, {
query: { method: 'GET', isArray: true },
create: { method: 'POST' }
}
);
$scope.objs = Geonames.query();
};
Ctrl.$inject = ['$scope','$resource'];
</script>
</head>
<body >
<div ng-app="myApp">
<div ng-controller="Ctrl">
{{objs.key}} - {{objs.value}}
</div>
</div>
</body>
</html>
我已经尝试使用从教程中获取的几个小变体来尝试这个示例,但它仍然无法正常工作。有什么帮助吗?
谢谢!
【问题讨论】:
标签: angularjs