【问题标题】:$elem.hide is not a function in angular-datatable$elem.hide 不是角度数据表中的函数
【发布时间】:2016-01-22 20:46:00
【问题描述】:

我想使用分页插件 angular-datatable 。我用 bower 安装了它,但它不起作用。它给出了以下错误

TypeError: $elem.hide 不是函数 在 Object.showLoading (http://localhost:8000/vendor/angular-datatables.js:698:15) 在 postLink (http://localhost:8000/vendor/angular-datatables.js:47:31) 在http://localhost:8000/vendor/angular.js:8783:44 在 invokeLinkFn (http://localhost:8000/vendor/angular.js:8789:9) 在 nodeLinkFn (http://localhost:8000/vendor/angular.js:8289:11) 在compositeLinkFn (http://localhost:8000/vendor/angular.js:7680:13) 在compositeLinkFn (http://localhost:8000/vendor/angular.js:7684:13) 在compositeLinkFn (http://localhost:8000/vendor/angular.js:7684:13) 在compositeLinkFn (http://localhost:8000/vendor/angular.js:7684:13) 在compositeLinkFn (http://localhost:8000/vendor/angular.js:7684:13)

我使用零配置, 这是我使用的html代码

<table datatable="" class="row-border hover">
    <thead>
        <tr>
            <th>ID</th>
            <th>First name</th>
            <th>Last name</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Foo</td>
            <td>Bar</td>
        </tr>
        <tr>
            <td>123</td>
            <td>Someone</td>
            <td>Youknow</td>
        </tr>
        <tr>
            <td>987</td>
            <td>Iamout</td>
            <td>Ofinspiration</td>
        </tr>
    </tbody>
</table>

【问题讨论】:

标签: angularjs npm bower angular-datatables


【解决方案1】:

我认为您以错误的顺序添加了 javascript 文件。

您需要按此顺序添加

  1. JQUERY
  2. ANGULAR
  3. JQUERY DATA-TABLE
  4. ANGULAR DATA-TABLE

别忘了将datatables模块添加到主模块中,

例如:angular.module('plunker', ['datatables']);

DEMO

很简单 - 如果您在angular.js 之后添加jquery.js,则剪切jquery.js 并将其放在angular.js 的顶部。

如果您使用的是bower,请更新bower.json 以满足上述更改。

【讨论】:

  • 我使用了 bower。仍然是同样的问题,我不知道为什么。我按该顺序添加。所有插件都正确链接到 html 的头部。我正在使用 gulp。在 app.js 中初始化“数据表”
  • angular.module('app',[ 'pascalprecht.translate', 'tmh.dynamicLocale', 'ngCookies', 'ngBootbox', 'ui-notification', 'dashboard', 'bank' , 'payment', 'userAccounts', 'accountSettings', 'credit-cards', 'help', 'contact', 'ngDialog', 'daterangepicker', 'datatables' ]);
  • 通过查看页面源来检查页面内容,并验证所有js 文件的顺序是否正确,如答案所示。如果仍然出现错误,请尝试创建 plnkr.co/edit
  • 很高兴为您提供帮助 :) 欢呼
  • 我遇到了同样的问题,并且 js 脚本的顺序是正确的(角度 js 在 3rparty.js 文件中使用 require('...') :
【解决方案2】:

另外,请确保您没有将 ng-jq 指令设置为空。相反,您想将其设置为 $jQuery

<html id="ng-app" ng-jq="$">

<html id="ng-app" ng-jq="jQuery">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-09
    • 2021-05-02
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    相关资源
    最近更新 更多