我用 netbeans 生成了一个简单的 java REST 服务,它正在运行,现在我需要制作一个 AngularJS Controller 和服务来获取一些数据(没什么特别的)。
我以前从未使用过 angularjs,我可能在 service.js
中犯了一个错误,因为我的 index.html
中没有显示任何内容。
controller.js
angular.module('app', ['ngRoute']);
angular.module('app', ['ngResource']);
angular.module('myApp', ['ngResource'])
.factory('myService',['$resource', function ($resource) {
return $resource('http://localhost:8080/IntelWebPlayer/webresources/ch.eiafr.iwp.backend.viewtimestamp', {}, {
query: {method: 'GET'}
})
}])
.controller('myCtrl', ['$scope','myService', function ($scope,myService) {
var b = myService.query();
alert(b);
$scope.timestamp = myService;
}]);
index.html
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://code.angularjs.org/1.2.3/angular.min.js"></script>
<script src="http://code.angularjs.org/1.2.3/angular-resource.js"></script>
<script src="js/controller.js"></script>
</head>
<body>
<div ng-controller="myCtrl">
{{ timestamp }}
</div>
</body>
</html>
你能帮助我或将我重定向到一个好的教程吗? 我唯一发现的是:http://draptik.github.io/blog/2013/07/13/angularjs-example-using-a-java-restful-web-service/
最佳答案
你可以试试这个AngularJS Step-by-Step: Services或 Spring's consuming RESTful w/AngularJS .其中大部分似乎是为 AngularJS 1.0 编写的,因此 1.2 中的一些差异可能会发挥作用。
关于java - 使用 Java (REST) 的 AngularJS 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20271025/