I'm facing difficulties when trying to create an ngTable. I can successfully render manually created arrays, but when I connect it to my api, it fails without any error message which is confusing. The $scope.data array is being filled as expected, but the new tableParams always ends up undefined.
Below is my HTML code:
<div ng-app="myApp" class="container-fluid" ng-controller="demoController as demo">
<div class="row">
<div class="col-xs-12">
<h2 class="page-header">Pharmacy Rebate Portal</h2>
</div>
</div>
<div class="row">
<div class="col-md-6">
<h3>Default configuration</h3>
<table ng-table="demo.tableParams" class="table table-condensed table-bordered table-striped">
<tr ng-repeat="row in $data">
<td data-title="'Manufacturer'">{{row.manufacturer | uppercase }} </td>
</tr>
</table>
</div>
</div>
</div>
I'm using ngTable version and Angular version 1.6.3. Any suggestions or ideas on how to resolve this issue?
$http.get('/api/rebates').
then(function (response) {
$scope.data = response.data;
$scope.tableParams = new NgTableParams({
page: 1, // show first page
count: 10, // count per page
sorting: {
foo: 'asc' // initial sorting
}
}, {
total: $scope.data.length, // length of data
getData: function ($defer, params) {
// use build-in angular filter
var orderedData = params.sorting() ?
$filter('orderBy')($scope.data, params.orderBy()) :
$scope.data;
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
});`