15

I am trying to use ng-table and tried adding it on many places but its giving error for all cases.

When I am adding ngTable in app.js, its giving:

Error: [$injector:unpr] Unknown provider: ngTableParamsProvider <- ngTableParams

When I am adding ngTable in controller, its giving undefined is not a function for controller.

How should I resolve it?

M.javid
  • 6,387
  • 3
  • 41
  • 56
Prateek
  • 342
  • 1
  • 3
  • 15
  • Can you create a plunker? My guess though is that you are not injecting ngTable into your module like this http://bazalt-cms.com/ng-table/example/1. – Ronald91 Jul 10 '14 at 13:05

4 Answers4

23

Another cause of this error is renaming of ngTableParams into NgTableParams in version 1.0.0. So, if you are using version 1.0.0, the code should look like this:

customModule.factory("customTable", function (NgTableParams) {

    function setupNgTable() {
        var parameters = {
            count: 10
        };

        var settings = {
            getData: function (params) {

            }
        };

        return new NgTableParams(parameters, settings);
    }
}
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
15

You need

  1. Add reference to <script src="....ng-table.js"></script> (more likely in in your index.html file)
  2. Inject ngTable to your angular module ie:

    var myApp = angular.module('myApp',['ngTable']);

  3. in controller

    myApp.controller('someCtrl', function($scope, ngTableParams) {....});

sylwester
  • 16,498
  • 1
  • 25
  • 33
  • 1
    I did the same but then it was giving undefined is not a function for controller. – Prateek Jul 10 '14 at 14:53
  • can you post your controller code or create plnkr ? – sylwester Jul 10 '14 at 14:56
  • did this also but still the same error undefined is not a function for controller. I am creating plnkr. Will post soon – Prateek Jul 10 '14 at 15:10
  • Hi 99% step 2. please double check I've just get error like you when I removed ngTable from array – sylwester Jul 10 '14 at 15:27
  • Thanks @sylwester . Actually I was using multiple controllers and in all, I was using angular.module('myApp',['ngTable']).controller('ctrl',...) So later on defining angular app in parent like you said in 2nd step worked to resolve problem. – Prateek Jul 11 '14 at 09:47
12

It looks like ngTableParams has been now changed to NgTableParams, starting with "N" instead of 'n'.

So, now the code will look something like this...

First, Add ng-table.js or ng-table.min.js link in your HTML code.

Then in your app.js or in the script part do like this...

var app = angular.module('XXX', ['ngTable']);

app.controller('XXXXX', function($scope, NgTableParams){

//-Inside wherever your using ngTableParams change it to NgTableParams

................

});

Hope this will help.

nplatis
  • 432
  • 2
  • 8
Sourav Sinha
  • 121
  • 1
  • 3
4

In order to use ngTable module you need to follow the steps in http://ng-table.com

Mind that NgTableParams injection is with capital N