I have a problem with ng-table, where the parameters that should be passed to my getData function are undefined. I am new to AngularJS and ng-table, so any help would be appreciated. I checked that REST causes the below code to work, directly calling them, so the problem is somewhere in my angular code / configuration.
Anyway, here is a pseudo-example of my controller. The actual code is on the intranet, so I canβt insert it directly, so please forgive any typos from the 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 corresponding html fragment:
<table ng-table="tableParams" class="table table-condensed table-striped"> <tr ng-repeat="row in data"> // row stuff here </tr> </table>
I added console.log statements before calling getData http, and the parameters print as undefined.
source share