简体   繁体   中英

AngularJS service with Java (REST)?

I generated a simple java REST service with netbeans and it is working and now I need to make a AngularJS controller and service to get some data (nothing special). I never used angularjs before and I probably made a mistake in the service.js because nothing is displaying in my 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>

Can you help me or redirect me to a good tutorial ? The only thing I found was : http://draptik.github.io/blog/2013/07/13/angularjs-example-using-a-java-restful-web-service/

You might try this AngularJS Step-by-Step: Services or Spring's consuming RESTful w/AngularJS . Most of these appear to be written with AngularJS 1.0 in mind, so some differences in 1.2 may come into play.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM