我是 AngularJS 的新手,我想检索 html 页面中的所有产品,但即使“/allProd”在没 Angular 情况下完美工作,它也不会显示任何内容
app.js
var app=angular.module('crm',[]);
app.controller('CRMController', function($scope,$http){
$scope.products=[];
$http.get('/allProd')
.then(function(data){
$scope.products=data;
});
});
index.html
<html data-ng-app="crm" >
<head>
<meta charset="ISO-8859-1">
<title>Catalog</title>
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.4-dist/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body data-ng-controller="CRMController">
<table class="table">
<thead>
<tr>
<th> REF </th><th> DES </th><th> PRICE </th>
</tr>
</thead>
<tbody >
<tr data-ng-repeat="p in products.content">
<td>{{p.reference}}</td>
<td>{{p.designation}}</td>
<td>{{p.price}}</td>
</tr>
</tbody>
</table>
<script type="text/javascript" src="angular/angular.min.js"></script>
<script type="text/javascript" src="angular/angular-sanitize.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>
PS:我使用的是 Angular 1.5.6 和 spring-boot 1.5.2.RELEASE
最佳答案
根据documentation for $http
实际的响应正文位于响应的 data
属性中。
$http.get('/allProd')
.then(function(response){
$scope.products = response.data;
});
关于javascript - AngularJS $http 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43219580/