javascript 错误:[$injector:unpr] 未知提供者:ngTableParamsProvider <- ngTableParams

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24676035/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 03:12:30  来源:igfitidea点击:

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

javascriptangularjsngtable

提问by Prateek

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

我正在尝试使用ng-table并尝试在许多地方添加它,但它在所有情况下都给出错误。

When I am adding ngTablein app.js, its giving:

当我添加ngTableapp.js 时,它给出:

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

错误:[$injector:unpr] 未知提供者:ngTableParamsProvider <- ngTableParams

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

当我添加ngTable控制器时,它给出的 undefined 不是控制器的函数。

How should I resolve it?

我该如何解决?

回答by Alexei

Another cause of this error is renaming of ngTableParamsinto NgTableParamsin version 1.0.0. So, if you are using version 1.0.0, the code should look like this:

此错误的另一个原因是在版本 1.0.0 中重命名为ngTableParamsinto 。因此,如果您使用的是 1.0.0 版,则代码应如下所示:NgTableParams

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

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

        var settings = {
            getData: function (params) {

            }
        };

        return new NgTableParams(parameters, settings);
    }
}

回答by sylwester

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) {....});

  1. 添加对<script src="....ng-table.js"></script>(更有可能在您的 index.html 文件中)的引用
  2. 将 ngTable 注入你的 angular 模块,即:

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

  3. 在控制器中

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

回答by Sourav Sinha

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

看起来ngTableParams现在已更改为NgTableParams,以“N”而不是“n”开头。

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

所以,现在代码看起来像这样......

First, Add ng-table.jsor ng-table.min.jslink in your HTML code.

首先,在您的 HTML 代码中添加ng-table.jsng-table.min.js链接。

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

然后在你的 app.js 或脚本部分做这样的......

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.

希望这会有所帮助。

回答by Thiago Bonfim

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

为了使用 ngTable 模块,您需要按照http://ng-table.com 中的步骤进行操作

Mind that NgTableParamsinjection is with capital N

注意NgTableParams注入是用大写 N