Error: 'undefined' is not a constructor (evaluating 'new ngTableParams')

12,248

This is because you are missing parameter. All have to matched as well

angular.module('MegaList')
       .controller('DisplayMegaList', ['$scope', '$http', 'ngTableParams', function($scope, $http, ngTableParams)
Share:
12,248
rishat
Author by

rishat

Updated on June 04, 2022

Comments

  • rishat
    rishat about 2 years

    I am trying to use ng-table but stuck with ngTableParams. I keep getting the

    [Error] Error: 'undefined' is not a constructor (evaluating 'new ngTableParams')
    

    error, no matter what things I try.

    The current code looks like

    $scope.tableParams = new ngTableParams({
        page: 1,
        count: 200,
        sorting: {
            name: 'asc'
        }
    }, {
        groupBy: 'area',
        total: TheData.length,
        getData: function($defer, params) {
            // use build-in angular filter
            var orderedData = params.sorting() ? $filter('orderBy')(TheData, params.orderBy()) : TheData;
            $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
        }
    });
    

    The app and controller are invoked with ngTable and ngTableParams:

    angular.module('MegaList', ['ui.bootstrap', 'ngTable']);
    angular.module('MegaList').controller('DisplayMegaList', ['$scope', 'ngTableParams', function($scope, $http, ngTableParams) {
        ...
    }
    

    I think I've already tried all the ways to compose 'ngTable', 'ngTableParams' and ngTableParams keywords together, but it still just doesn't work.

    What should I try then?