Starting with AngularJS. 'NgTableParams' is not defined
Asked Answered
V

2

7

I'm starting with my first AngularJS Application. I try with angular-gulp-browserify-starter, and work fine. But now I try add ngTable, but gulp build says:

'NgTableParams' is not defined.

I'm trying follow these steps: http://ng-table.com/.

1- Add ng-table with bower

bower install ng-table --save

2- Add module to 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- And this is my controller

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

Where and how I put this?

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

I have the HTML like ng-table sitle instructions says.

Thanks!

Vegetarian answered 29/12, 2015 at 23:41 Comment(2)
I add './libs/ng-table/dist/css/ng-table.css', and './libs/ng-table/dist/ng-table.js' to gulpfile. No more errors with gulp build, but don't show table :SVegetarian
did you fix your problem ?Ancestress
J
23
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});
        });
    }
}]);

This is the easiest implementation in my option

Jurisprudent answered 1/3, 2016 at 11:3 Comment(0)
A
9

i got the same error, the documentation is missing a point : -> you have to inject ngTableParams in the controller

I'm not sur of the syntax (i don't use this one)

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;
Ancestress answered 5/1, 2016 at 15:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.