1
我與AngularJS一個新手,我想以檢索所有產品在HTML頁面中,但它說明不了什麼,即使「/ allProd」完美的作品無角
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:我使用角1.5.6和彈簧引導1.5.2.RELEASE
你確認了你的'data'變量是否爲null? – Barak
快速瀏覽一下你的html
它的作品謝謝你! – MyungHee
回答
按照documentation for
$http
實際響應主體處於響應的data
屬性。來源
2017-04-04 23:54:33
我試過你的建議,但沒有改變 – MyungHee
你將不得不做
另外,在您的NG-重複就不得不提一個數組,但似乎你的初始化和賦值不同步爲$在scope.products控制器。
如果
response.data.products
是不是一個數組,沒有一點聲明$scope.products
作爲數組來源
2017-04-05 03:28:51
我試了response.data,但沒有改變 – MyungHee
這是因爲成功接收的數據的另一個屬性叫裏面的數據,其實際持有所需的產品數據。
嘗試改變代碼
來源
2017-04-05 03:31:28
我以前試過但沒有改變 – MyungHee
在你的.js文件改變後: $ scope.products = data.data; 「P在產品」
你並不需要。內容:
然後,你的HTML文件從「在products.content P」 以下更改。因爲.content不是數據結構的一部分。
來源
2017-04-05 17:41:56 dowgwi
啊...查理伍在這上打了我。 – dowgwi
相關問題