Nooby Question here. I have test sales data in a JSON Format and want to display the data in a table using Angular JS.
Here is the Angular Code.
var SalesDataApp = angular.module("SalesDataApp", []);
app.factory("services", ['$http', function ($http) {
var serviceBase = '/api/sales';
var obj = {};
obj.getCustomers = function () {
return $http.get(serviceBase);
};
return obj;
}]);
app.controller('SalesDataController', function ($scope, services) {
services.getCustomers().then(function (data) {
alert(JSON.stringify(data));
$scope.customers = data;
});
});
I know theres better ways of doing this but im just delving into Angular... Heres my HTML..
<div ng-controller="SalesDataController">
<table class="table table-striped" >
<tr><th>ID</th>
</tr>
<tr ng-repeat="a in salesData">
<td>{{a.Index}}</td>
</tr>
</table>
</div>
Ive done a test to see if angular is working and thats a winner, but the code isnt displaying anything. Exactly where am I going wrong?
Thanks
customersin the HTML?console.log($scope.customers)looks like in your.then()$scope.customers = data;call - doconsole.log($scope.customers)- and to see your console, press F12 (most browsers anyways) - or find it in the dev tools. It works WAAAAY nicer thanalert