2016-08-24 108 views
0

问题重复以在UI中显示表格。该表的值从Access DB中获取,并通过servlet获取。我的角度控制器能够正确调用servlet,并且servlet能够返回json。但是ng-repeat会抛出一个错误。使用Angularjs中的ngRepeat问题

错误:[ngRepeat:iexp]在形式预期表达 '收集 [轨道由ID]',但得到了 '项'。下面

代码:

<!DOCTYPE HTML> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<title>QuoteDetails</title> 
<link href="css/bootstrap.css" rel="stylesheet"> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
<script src="js/bootstrap.min.js"></script> 

</head> 
<body> 
<div class="container" ng-app="myApp"> 
     <div ng-controller="MyController" ng-init="getDataFromServer()"> 
<table class="table table-striped table-bordered" id="example" style="border-collapse: collapse, width: 100%"> 
     <thead> 
      <tr> 
       <th>Quote No</th> 
       <th>Quote Amt</th> 
       <th>Quote Contact</th> 
       <th colspan=2>Action</th> 
      </tr> 
     </thead> 
     <tbody> 
      <!-- <c:forEach var="user" items="${users}"> 
       <tr> 
        <td><c:out value="${user.quoteNo}" /></td> 
        <td><c:out value="${user.quoteAmt}" /></td> 
        <td><c:out value="${user.quoteContact}" /></td> 
       </tr> 
      </c:forEach> --> 
      <tr ng-repeat=item in user track by $index> 
       <td>{{item.quoteNo}}</td> 
       <td>{{item.quoteAmt}}</td> 
       <td>{{item.quoteContact}}</td> 
      </tr> 
     </tbody> 
    </table> 
    </div> 
    </div> 
    <p><a href="UserController?action=insert">Add User</a></p> 
    <script src="js/angular.js"></script> 
    <script> 
var app = angular.module('myApp', []); 

app.controller("MyController", ['$scope', '$http', function($scope, $http) { 
     $scope.test="hellos"; 
     console.log($scope.test); 
     $scope.getDataFromServer = function() { 
       $http({ 
         method : 'GET', 
         url : 'UserController' 
       }).success(function(data, status, headers, config) { 
         $scope.user= data; 
         console.log($scope.user); 
       }).error(function(data, status, headers, config) { 
         // called asynchronously if an error occurs 
         // or server returns response with an error status. 
       }); 

     }; 
}]); 
</script> 
</body> 
</html> 

可否请你让我知道什么是问题?

+0

不应该是'item in user'而不是'user in user'吗? – Tomer

回答

2

ng-repeat值必须在引号内!

<tr ng-repeat="item in user track by $index">