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 badges3 Answers
Reset to default 3This 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_;
}));