I am running into a problem using ng-table where the params that should be passed into my getData function is undefined. I an new to AngularJS and ng-table, so any help would be appreciated. I have verified that the REST calls in the code below work by directly invoking them, so the problem is somewhere in my angular code/configuration.
Anyhow, here is a pseudo-example of my controller. The actual code is on an intranet, so I can't paste it directly, so pardon any typos from transcription. Using ng-table 1.0.0 and angular 1.5.8:
myApp.controller('myCtrl', ['$scope', '$http', 'NgTableParams',
function($scope, $http, NgTableParams) {
$http.get('services/data/count').success(function(data) {
// this works fine
$scope.totalRows = data.rowCount;
});
$scope.tableParams = new NgTableParams({
page: 1
count: 20
}, {
total: $scope.totalRows,
getData: function($defer, params) {
// this line fails with params being undefined
$http.get('/services/data/' + params.page() + '/' + params.count()) {
.success(function(data) {
$scope.data = data;
$defer.resolve(data);
});
}
});
}]);
And here is the relevant piece of html:
<table ng-table="tableParams" class="table table-condensed table-striped">
<tr ng-repeat="row in data">
// row stuff here
</tr>
</table>
I've inserted console.log statements before the getData http call, and params is printing out as undefined.
console.log
your$defer
variable, you'll see the object you were expectingparams
to hold. – Keniakenilworth$http.success
is deprecated. Usethen(function(response), function(rejectionReason))
instead. – Keniakenilworth