javascript 错误:“未定义”不是构造函数(正在评估“新 ngTableParams”)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26121115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: 'undefined' is not a constructor (evaluating 'new ngTableParams')
提问by rishat
I am trying to use ng-table but stuck with ngTableParams. I keep getting the
我正在尝试使用 ng-table 但坚持使用 ngTableParams。我不断得到
[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:
使用 ngTable 和 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.
我想我已经尝试了所有组合'ngTable'
,'ngTableParams'
和ngTableParams
关键字的方法,但它仍然不起作用。
What should I try then?
那我应该尝试什么?
回答by jprism
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)
回答by Kamil R
It looks like you create controller on a different module. Try to use MegaList.controller(...)
instead of FloristList.controller(...)
.
看起来您在不同的模块上创建控制器。尝试使用MegaList.controller(...)
而不是FloristList.controller(...)
.
回答by Sylvia
I had a similar problem and just copying the beforeEach
from this sample helped me:
https://docs.angularjs.org/guide/unit-testing
我有一个类似的问题,只是beforeEach
从这个示例中复制帮助了我:https:
//docs.angularjs.org/guide/unit-testing
beforeEach(inject(function(_$controller_){
// The injector unwraps the underscores (_) from around the parameter names when matching
$controller = _$controller_;
}));