从AngularJS开始。 ' NgTableParams'没有定义

时间:2015-12-29 23:41:22

标签: angularjs ngtable

我从我的第一个AngularJS应用程序开始。我尝试angular-gulp-browserify-starter,并且工作正常。但现在我尝试添加ngTable,但 gulp build 说:

'NgTableParams' is not defined.

我尝试按照以下步骤操作:http://ng-table.com/

1-添加带凉亭的ng-table

bower install ng-table --save

2-将模块添加到app.js

var angular = require('angular');

angular.module('myApp', ['ngTable']);   // this is the new line

module.exports = angular.module('myApp',
    [
        require('./common/common.js').name,
        require('./modules').name
    ])
    .config(require('./appConfig'))
    .constant('version', require('../package.json').version)
    .run(require('./common/common-init.js'));

3-这是我的控制器

'use strict';
function TableCtrl($scope) {
    $scope.testVar = 'This my test for ngtable';
}
TableCtrl.$inject = ['$scope'];
module.exports = TableCtrl;

我把它放在哪里以及怎么做?

var self = this;
var data = [{name: "Moroni", age: 50} /*,*/];
self.tableParams = new NgTableParams({}, { dataset: data});

我有像ng-table sitle说明那样的HTML。

谢谢!

2 个答案:

答案 0 :(得分:22)

var App = angular.module('AdminApp.Report.Controllers.Stores', ['ngMaterial','ngTable']);

App.controller('SomeController', ['$scope', '$http','NgTableParams', function ($scope, $http, NgTableParams) {

        httpService.PostApiRequest(request,'/api/someUrl').then(function(data) {
            $scope.tableParams = new NgTableParams({}, { dataset: data});
        });
    }
}]);

这是我选项中最简单的实现

答案 1 :(得分:9)

我得到了同样的错误,文档缺少一点: - >你必须在控制器中注入ngTableParams

我不是语法(我不使用这个)

function TableCtrl($scope) {
    $scope.testVar = 'This my test for ngtable';
    // if this is your controller, every var you put in the $scope will be accessible in the view

    var data = [{name: "Moroni", age: 50} /*,*/];
    $scope.tableParams = new NgTableParams({}, { dataset: data});   
}
TableCtrl.$inject = ["$scope","NgTableParams", "ngTableSimpleList"];
module.exports = TableCtrl;