2017-04-18 68 views
1

我成功地從php服務器使用$ http獲取數據。但我不知道如何使用ngRepear以表格形式顯示數據,因爲所有的數據都在幾個不同的項目中。我將把數據的所有對象顯示在表格的不同行中。以下顯示了我從php服務器獲得的數據。Angularjs:ngRepeat列出來自服務器的所有數據

enter image description here

+0

這個數據添加到在控制器中一個範圍變量,然後在視圖中使用ngrepeat顯示 –

回答

1

下面的代碼一瞥可以給你的想法

$scope.retrievedData = []; 
 
//retrieve data from your server 
 
//take the data into above scope variable
<table> 
 
<tr ng-repeat = "data in retrievedData"> 
 
<td>data.AssetDescription</td> 
 
<td>data.AssetNumber</td> 
 
<td>data.ComputerName</td> 
 

 
</tr> 
 
</table>

0

您需要添加數據到控制器變量:

控制器

function YourController($scope, $http) { 
    $scope.tableData = []; 

    $http.get('url').then(function(result) { 
     $scope.tableData = result.data; 
    }); 
} 

模板

<table> 
    <thead> 
     <tr> 
      <th>Description</th> 
      <th>Computer name</th> 
      <th>Borrow date</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr ng-repeat="row in tableData "> 
      <td>{{row.data.AssetDescription}}</td> 
      <td>{{row.data.ComputerName}}</td> 
      <td>{{row.data.borrowDate}}</td> 
     </tr> 
    </tbody> 
</table> 
相關問題