When testing the code below the query returns the correct data but when I try to display the return data it does not display in my table. If I simply copy the return data and make that the value of $scope.products it displays just fine. Is there something special that have to do to the dynamic data to get it to work? I am new to angularjs so I am still learning.
Return JSON data
{NAME: "21st Amendment Blood Orange IPA", ID: 327},{NAME: "3 Daughters Blonde", ID: 328},{NAME: "90 Shillings", ID: 329},{NAME: "Avrey Ellie's Brown", ID: 330},{NAME: "Bed Head Red Ale", ID: 331},{NAME: "Bell's Two Hearted", ID: 332},{NAME: "Berkshire Steel Rail", ID: 333}
angularjs code
var app = angular.module("root", [])
app.controller("repeater", ["$scope", "$http", function($scope, $http) {
$http({method: 'GET', url: 'http://server/angularjs/cfc/sqldata.cfc?method=products'})
.then(function (response) {
var str = '[';
for(var i in response.data){
str += '{NAME: ' + '"' + response.data[i].NAME + '", ID: ' + response.data[i].ID + '},';
}
str += ']';
//console.log(str);
$scope.products = str;
//document.write(str);
});
}]);
HTML code
<div ng-controller="repeater">
<table border="1" bordercolor="#000000" cellpadding="0" cellspacing="0">
<thead>
<tr>
<td style="font-weight:bold">Index</td>
<td style="font-weight:bold">Item Id</td>
<td style="font-weight:bold">Item Name</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="product in products track by $index" ng-class="{oddRow: $odd}">
<td>{{$index}}</td>
<td>{{product.ID}}</td>
<td>{{product.NAME}}</td>
</tr>
</tbody>
</table>
</div>