【问题标题】:AngularJS get data from webapi and store in tableAngularJS 从 webapi 获取数据并存储在表中
【发布时间】:2017-08-16 15:19:17
【问题描述】:

我创建了一个 rest web api 并使用 AngularJS,我想接收这些 json 数据并将它们存储在一个表中。我是 AngularJS 的新手。我能够获取所有 json 数据,但我想将它们分成每一行。我不确定我是否正确,但这是我的代码:

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;
    });
});

【问题讨论】:

  • 这是什么&lt;tr ng-repeat=" quiz values"&gt;

标签: html angularjs json rest


【解决方案1】:

你的ng-repeat不好,

如果我了解您的结果数组在 $scope.result 中,那么您必须这样做 ng-repeat

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

【讨论】:

  • 哦,好吧,我想在 ng-repeat="" 之后,它应该是某种 cmets。现在明白了,谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-02
  • 2017-07-26
  • 2016-10-06
  • 2010-11-13
  • 2023-03-16
  • 1970-01-01
相关资源
最近更新 更多