【发布时间】:2017-02-21 02:09:37
【问题描述】:
我实现了一个后端,基于 Spring boot 向前端提供数据。它工作正常。当我使用 chrome 浏览本地主机时,它可以工作 网址:http://localhost:4983/employee/ALL/
回复:
'[{"id":1,"name":"ALFRED","dept":"871m","email":"woodspring.toronto@gmail.com","salary":120000},
{"id":2,"name":"FRANK","dept":"TCTO","email":"tzuchi.toronto@gmail.com","salary":920000},
{"id":3,"name":"NANCY","dept":"TDSB","email":"nancy.tseng@gmail.com","salary":620000},
{"id":4,"name":"TONG","dept":"NYGH","email":"tony.tang@gmail.com","salary":720000},
{"id":5,"name":"CINDY","dept":"University Of Victoria","email":"cindy.huang@uvic.edu","salary":9987654},
{"id":6,"name":"CINDY HUANG","dept":"University Of Victoria","email":"cindy.huang@uvic.edu","salary":9987654}]'
但是,当我使用 HTML 和 Angular JS 来 $http 时,数据并没有按预期显示。
这是我的 Angular JS 代码:
<html>
<head>
<title>Angular JS Includes</title>
<style>
table, th, td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f2f2f2;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
</head>
<body>
<script>
function employeeController($scope, $http) {
$http({method: 'GET', url: 'http://localhost:4983/employee/ALL/'} )
.success(function (response) {
$scope.employees = response;
console.log( $scope.employees);
$scope.context = "IT works";
});
}
</script>
<h2>AngularJS Employee Application</h2>
<div ng-app="" ng-controller="employeeController">
{{ context }}
{{ employees[0].id }}
<table>
<tr>
<th>Employee ID</th>
<th>Employee Name</th>
<th>Employee Dept</th>
<th>employee Email</th>
<th>employee Salary</th>
<th>{{ msg }}</th>
</tr>
<tr ng-repeat="empl in employees">
<td>{{ empl.id }}</td>
<td>{{ empl.name }}</td>
<td>{{ empl.dept }}</td>
<td>{{ empl.email }}</td>
<td>{{ empl.salary }}</td>
<td>{{ msg }}</td>
</tr>
</table>
</div>
{{ msg }}
<script src='http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js'></script>
</body>
</html>
当我在 Chrome 上浏览此页面时,我可以看到后端 spring-boot 已被调用并响应数据。但是,前端不显示它。谁能看到我做错了什么?
【问题讨论】:
-
你在哪里定义了模块??
-
您检查浏览器控制台是否有任何错误?还是日志的值?