Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ng-Table tableParams

I have am following the first example of ng-table (http://bazalt-cms.com/ng-table/example/1).

Everything seems to work except tableParams. As soon as I include it in the controller nothing is display in the page.

The difference between the example and my code is that I load data from a json service:

angular.module('mean.cars').controller('CarsController', ['$scope', '$stateParams', '$location', 'Global', 'Cars',
function ($scope, $stateParams, $location, Global, Cars, ngTableParams) {
    $scope.global = Global;
    var data = Cars.query();

$scope.tableParams = new ngTableParams({
    page: 1,            // show first page
    count: 10           // count per page
}, {
    total: data.length, // length of data
    getData: function($defer, params) {
        $defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
    }
});

Cars.query(); is working well (tested it). So what am I missing? There is a javascript error: "undefined is not a function occuring" at the following line:

$scope.tableParams = new ngTableParams({
like image 422
Tyvain Avatar asked Mar 28 '14 00:03

Tyvain


2 Answers

I'm also new with Angular and also with ngTable plugin, but I think your problem is that you are not adding the reference for ngTable on your module.

angular.module('mean.cars', ['ngTable'])
       .controller('CarsController', ['$scope', 
                                      '$stateParams', 
                                      '$location', 
                                      'Global', 
                                      'Cars', 
                                      'ngTableParams', 
            function ($scope, $stateParams, $location, Global, Cars, ngTableParams) { ...

You missed the 'ngTable' on the module dependency, and also the 'ngTableParams' on your controller.

Hope this helps you.

like image 61
Elwi Avatar answered Oct 16 '22 19:10

Elwi


I'm not sure where ngTableParams comes from, but you're not injecting it:

['$scope', '$stateParams', '$location', 'Global', 'Cars',
function ($scope, $stateParams, $location, Global, Cars, ngTableParams) {

Either that should be like this:

['$scope', '$stateParams', '$location', 'Global', 'Cars', 'ngTableParams',
function ($scope, $stateParams, $location, Global, Cars, ngTableParams) {

Or like this:

['$scope', '$stateParams', '$location', 'Global', 'Cars',
function ($scope, $stateParams, $location, Global, Cars) {    
like image 21
Mathew Berg Avatar answered Oct 16 '22 18:10

Mathew Berg