Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html AngularJS https得到响应,但没有';t显示_Html_Angularjs_Json - Fatal编程技术网

Html AngularJS https得到响应,但没有';t显示

Html AngularJS https得到响应,但没有';t显示,html,angularjs,json,Html,Angularjs,Json,我实现了一个后端,以基于Spring boot向前端提供数据。它很好用。当我使用chrome浏览本地主机时,它工作正常 网址: 答复: '[{"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":9200

我实现了一个后端,以基于Spring boot向前端提供数据。它很好用。当我使用chrome浏览本地主机时,它工作正常 网址:

答复:

'[{"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时,数据并没有按预期显示

以下是我的代码:


角JS包括
表,th,td{
边框:1px纯灰;
边界塌陷:塌陷;
填充物:5px;
}
表tr:第n个子项(奇数){
背景色:#F2F2;
}
表tr:第n个子项(偶数){
背景色:#ffffff;
}
函数employeeController($scope,$http){
$http({方法:'GET',url:'http://localhost:4983/employee/ALL/'} )
.成功(功能(响应){
$scope.employees=响应;
console.log($scope.employees);
$scope.context=“它有效”;
});
}
AngularJS员工应用程序
{{context}}
{{employees[0].id}
员工ID
员工姓名
员工部
员工电子邮件
员工工资
{{msg}}
{{emp.id}
{{emp.name}
{{emp.dept}
{{emp.email}
{{emp.salary}
{{msg}}
{{msg}}
来自 响应对象具有以下属性:

数据{string | Object}–使用转换函数转换的响应体。 状态–{number}–响应的HTTP状态代码。 headers–{function([headerName])}–Header getter函数。 config–{Object}–用于生成请求的配置对象。 statusText–{string}–响应的HTTP状态文本


在这种情况下,使用:$scope.employees=response.data

对于初学者,参考$http服务文档:

$http legacy promise方法
success
error
已被弃用。改用标准的
然后
方法

尝试将代码更改为

function employeeController($scope, $http) {
  $http({
    method: 'GET',  
    url: 'http://localhost:4983/employee/ALL/'
  }).then(function (response) {
      $scope.employees =  response;
      console.log($scope.employees); //check what this outputs
      $scope.context = "IT works";
    });
}
当然你也知道,给我们本地主机URL在这里没有任何用处


此外,代码可能有很多错误,如果您可以检查浏览器控制台是否有任何错误,或者至少检查控制台是否有
console.log($scope.employees)

您在哪里定义了模块?您是否检查了浏览器控制台是否有任何错误?还是日志的值?