簡體   English   中英

帶有 Java (REST) 的 AngularJS 服務?

[英]AngularJS service with Java (REST)?

我用 netbeans 生成了一個簡單的 java REST 服務並且它正在工作,現在我需要制作一個 AngularJS 控制器和服務來獲取一些數據(沒什么特別的)。 我以前從未使用過 angularjs,我可能在service.js犯了一個錯誤,因為我的index.html沒有顯示任何內容。

控制器.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;
}]);

索引.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: ServicesSpring's 消費 RESTful w/AngularJS 其中大部分似乎是用 AngularJS 1.0 編寫的,因此 1.2 中的一些差異可能會發揮作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM