Ng-Table tableParams

Tyv*_*ain 7 angularjs ngtable

我正在关注ng-table的第一个例子(http://bazalt-cms.com/ng-table/example/1).

除了tableParams之外,一切似乎都有效.只要我将其包含在控制器中,页面中就不会显示任何内容.

示例和我的代码之间的区别是我从json服务加载数据:

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()));
    }
});
Run Code Online (Sandbox Code Playgroud)

Cars.query(); 运作良好(测试过).那我错过了什么?有一个javascript错误:"undefined不是函数出现"在以下行:

$scope.tableParams = new ngTableParams({
Run Code Online (Sandbox Code Playgroud)

Elw*_*lwi 21

我也是Angular和ngTable插件的新手,但我认为你的问题是你没有在你的模块上添加ngTable的引用.

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

您错过了模块依赖项的'ngTable',以及控制器上的'ngTableParams'.

希望这对你有所帮助.


Mat*_*erg 5

我不确定ngTableParams来自哪里,但你不是在注入它:

['$scope', '$stateParams', '$location', 'Global', 'Cars',
function ($scope, $stateParams, $location, Global, Cars, ngTableParams) {
Run Code Online (Sandbox Code Playgroud)

要么是这样的:

['$scope', '$stateParams', '$location', 'Global', 'Cars', 'ngTableParams',
function ($scope, $stateParams, $location, Global, Cars, ngTableParams) {
Run Code Online (Sandbox Code Playgroud)

或者像这样:

['$scope', '$stateParams', '$location', 'Global', 'Cars',
function ($scope, $stateParams, $location, Global, Cars) {    
Run Code Online (Sandbox Code Playgroud)