javascript - Error: 'undefined' is not a constructor (evaluating 'new ngTableParams') - Stack Ov

I am trying to use ng-table but stuck with ngTableParams. I keep getting the[Error] Error: 'undefi

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 pose 'ngTable', 'ngTableParams' and ngTableParams keywords together, but it still just doesn't work.

What should I try then?

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 pose 'ngTable', 'ngTableParams' and ngTableParams keywords together, but it still just doesn't work.

What should I try then?

Share Improve this question edited Oct 1, 2014 at 12:43 rishat asked Sep 30, 2014 at 12:38 rishatrishat 8,3764 gold badges51 silver badges72 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

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)

It looks like you create controller on a different module. Try to use MegaList.controller(...) instead of FloristList.controller(...).

I had a similar problem and just copying the beforeEach from this sample helped me: https://docs.angularjs/guide/unit-testing

beforeEach(inject(function(_$controller_){
  // The injector unwraps the underscores (_) from around the parameter names when matching
  $controller = _$controller_;
}));

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745147754a4613724.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信