2017-04-18 2 views
1

PHPサーバーから$ http getを使用してデータを正常に取得しました。しかし、すべてのデータがほとんど別のプロジェクトにあるため、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> 
関連する問題