Я установил все это вручную, и когда приложение запускает Spring-Boot, отображает страницу index.html с файлом AngularJS <div ng-view></div>
, мои файлы конфигурации работают в моем проекте AngularJS, но теперь я пытаюсь получить информацию из моих успокоительных сервисов, и кажется, что они больше не вызываются. Довольно много раз, когда он передается index.html, угловой контроль.Службы RESTful с Spring-boot не используются при внедрении AngularJS
indexController.java
@RestController
public class IndexController {
@RequestMapping("/")
public String index(){
System.out.println("Looking in the index controller.........");
return "index";
}
}
FormRestController.java
@RestController
public class FormRestController {
@Autowired
UserService userService;
//-------------------Retrieve All Users--------------------------------------------------------
@RequestMapping(value = "/getUsers", method = RequestMethod.GET)
public ResponseEntity<List<User>> listAllUsers() {
System.out.println("listAllUsers() is being called inside RestController............");
List<User> users = userService.findAllUsers();
if(users.isEmpty()){
return new ResponseEntity<List<User>>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<List<User>>(users, HttpStatus.OK);
}
users.config.js
angular.module('myApp')
.config(['$routeProvider', function ($routeProvider){
$routeProvider.when('/users', {
templateUrl: 'app/scripts/Customers/users.html',
controller: 'UsersController'
}).otherwise({redirectTo:'/'});
}]);
usersService.js
angular.module('myApp')
.factory('usersService',['$http', '$q', function($http,$q){
return {
fetchAllUsers: function(){
console.log("inside fetchAllUsers");
return $http.get('/getUsers')
.then(
function(response){
return response;
},
function(errResponse){
console.error("Error while fetching customers"+errResponse);
return $q.reject(errResponse);
}
);
}
}
}]);
users.controller.js
angular.module('myApp')
.controller('UsersController', ['$scope', 'usersService', function($scope,
usersService){
this.user = {id:null, username:'', address:'',email:''};
this.users = [];
var self = this;
this.fetchAllUsers = function(){
var usersSelf = self;
usersService.fetchAllUsers()
.then(
function(d){
usersSelf.users = d
},
function(errResponse){
console.error("Error while catching something"+errResponse);
}
);
}
}]);
users.html
<div ng-controller="UsersController as ctrl">
<table class="table table-hover" ng-init="ctrl.fetchAllUsers()">
<thead>
<tr>
<th>ID.</th>
<th>Name</th>
<th>Address</th>
<th>Email</th>
<th width="20%"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="u in ctrl.users">
<td>{{u.id}}</td>
<td>{{u.username}}</td>
<td>{{u.address}}</td>
<td>{{u.email}}</td>
</tr>
</tbody>
</table>
home.html (Это корневой страницы)
<div>
<h2>You have landed on the home page!!!</h2>
<a ng-href="#/users">Click here to go to the next page...</a>
</div>
выход
'this' - это не то, что вы думаете, это внутреннее обещание. Храните ссылку на 'this' и используйте эту ссылку – charlietfl