Hi I am trying to learn Spring RESTful Webservice with Angular js. I have Created a Simple Controller that returns Json Values
@RestController
public class TestController {
@RequestMapping("/greeting")
public GreetingModel greeting(@RequestParam(value="name",defaultValue="World")String user){
GreetingModel greetingModel = new GreetingModel();
greetingModel.setId("123");
greetingModel.setContent(user);
return greetingModel;
}
I get the Following Output on my chrome browser
{"id":"123","content":"World"}
I have created a html file as below
<html ng-app>
<head>
<title>Hello AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script src="js/hello.js"></script>
</head>
<body>
<div ng-controller="Hello">
<p>The ID is {{greeting.id}}</p>
<p>The content is {{greeting.content}}</p>
</div>
</body>
</html>
hello.js
function Hello($scope, $http) {
return $http.get('http://localhost:8080/greeting').
success(function(data) {
$scope.greeting = data;
});
}
I get the Following Output
The ID is
The content is
But when I Replace the the http.get in hello.js file
$http.get('http://localhost:8080/greeting')
with
$http.get('http://rest-service.guides.spring.io/greeting')
provide by Spring IO at https://spring.io/guides/gs/consuming-rest-angularjs/ I get the output
The ID is 581
The content is Hello, World!
Is there some issues using localhost