controller code
@RequestMapping(value="/welcomes", method = RequestMethod.GET, produces="MediaType.application/json")
public @ResponseBody ModelAndView welcome(@ModelAttribute UserBean userBean)
{
List<UserBean> usernames=new ArrayList<UserBean>();
usernames = retrievedataservice.findAllUsers(userBean);
System.out.println(usernames.size());
return new ModelAndView("welcomes", "usernames", usernames);
}
angular js code
<script>
var app = angular.module('myApp', []);
app.controller('UserController', function($scope, $http, $location){
$scope.usernames=[];
var url = $location.absUrl() + "http://localhost:8080/SpringAngular/welcomes";
$http.get(url).then(function (response)
{
$scope.usernames = response.records;
},function error(response)
{
$scope.postResultMessage = "Error with status: " + response.statusText;
});
});
</script>
<div data-ng-app="myApp" data-ng-controller="UserController">
<table border="1" width="50%" height="50%">
<tr><th>user_name</th><th>phone</th><th>email</th></tr>
<tr data-ng-repeat="user in usernames">
<td>{{user.username}}</td>
<td>{{user.phone}}</td>
<td>{{user.email}}</td>
</tr>
</table>
Actually, the controller returns the list of data, but angular js cannot get the data. It returns the null values. it cannot integrate with angular js and controller.
var url = $location.absUrl() + "http://localhost:8080/SpringAngular/welcomes";does not look right.