Senthil Senthil - 1 year ago 100
HTML Question

Issue with ngRepeat in Angularjs

repeat to display the table in UI. The value for the table is fetched from Access DB and it is through servlet. My angular controller is able to call the servlet properly and servlet is able to return the json. However ng-repeat is throwing an error .

Error: [ngRepeat:iexp] Expected expression in form of 'item in collection[ track by id]' but got 'item'.

code below :

<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">
<link href="css/bootstrap.css" rel="stylesheet">
<script src=""></script>
<script src="js/bootstrap.min.js"></script>

<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%">
<th>Quote No</th>
<th>Quote Amt</th>
<th>Quote Contact</th>
<th colspan=2>Action</th>
<!-- <c:forEach var="user" items="${users}">
<td><c:out value="${user.quoteNo}" /></td>
<td><c:out value="${user.quoteAmt}" /></td>
<td><c:out value="${user.quoteContact}" /></td>
</c:forEach> -->
<tr ng-repeat=item in user track by $index>
<p><a href="UserController?action=insert">Add User</a></p>
<script src="js/angular.js"></script>
var app = angular.module('myApp', []);

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


Could you please let me know what is the issue ?

Answer Source

ng-repeat value have to be inside quotes!

<tr ng-repeat="item in user track by $index">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download