2017-08-16 17 views
0

我創建了一個休息web api並使用AngularJS,我想接收這些json數據並將它們存儲在一個表中。我是AngularJS的新手。我能夠獲得所有的json數據,但我想將它們分成每一行。我不知道如果我做的正確與否,但這裏是我的代碼:AngularJS從webapi獲取數據並存儲在表

的index.html

<!DOCTYPE html> 
<html ng-app="demoApp"> 
<head> 
<meta charset="UTF-8"> 
<title>Angular</title> 
<script src="lib/angular.js"></script> 
<script src="angularDemo.js"></script> 
</head> 
<body> 
    <div ng-controller="demoController"> 
     <table> 
      <tr> 
       <th>Id</th> 
       <th>Question</th> 
      </tr> 
      <tr ng-repeat=" quiz values"> 
       <td>{{result.id}}</td> <!-- Does not get any value--> 
       <td>{{result.question}}</td> <!-- Does not get any value--> 
      </tr> 
     </table> 
     <h1>{{result}}</h1> <!-- gets all the json data --> 
    </div> 
</body> 
</html> 

JS

var app = angular.module("demoApp", []); 

app.controller("demoController", function($scope, $http) { 
    $http.get("http://localhost:8080/quiz/webapi/quiz") 
    .then(function(response) { 
     $scope.result = response.data; 
    }); 
}); 
+0

這是什麼?」? –

回答

1

ng-repeat不好,

如果我明白你的排列結果是在$scope.result,那麼你必須做這樣的ng-repeat

<tr ng-repeat="row in result"> 
    <td>{{row.id}}</td> 
    <td>{{row.question}}</td> 
</tr> 
+0

噢好吧,我想在ng-repeat =「」之後,它應該是某種評論。現在我明白了,謝謝 – bubbles2189

相關問題