【问题标题】:jQuery not being found by icheck using webpack (Angular 2)icheck 使用 webpack (Angular 2) 找不到 jQuery
【发布时间】:2016-06-01 06:30:59
【问题描述】:

我正在使用 Angular 2、webpack 编写应用程序,并且我正在使用需要 jQuery 的 icheck 前端库 (http://icheck.fronteed.com/)。

因此,我在我的组件中需要它们:

var jQuery: any = require("jquery");
require('../../../js/jquery.icheck.min.js');
require('../../../css/checkbox/orange.css');

使用 webpack 服务器和 npm 成功构建,但在浏览器中出现错误:

Uncaught ReferenceError: jQuery is not defined (jquery.min.icheck.js:11)

我以前在 Angular 2 组件中使用过这个插件,但我从来没有遇到过这样的问题。我已将当前应用程序与正在运行的应用程序进行了比较,但我看不出任何差异;它应该工作!

我现在真的反对它,必须为星期一做好准备。有人遇到过这样的问题吗?

【问题讨论】:

    标签: jquery node.js angular webpack icheck


    【解决方案1】:

    请尝试删除

    var jQuery: any = require("jquery");
    

    将这些代码添加到 ts 文件的标题中。

    declare var jQuery;
    

    【讨论】:

      【解决方案2】:

      试试这个

      declare var $: any;
      
      @Component({
        selector: 'foo'
      })
      
      export class FooBarComponent {
          $: any = $;
          constructor(el: ElementRef) {
              // use this way
              this.$(".fooBar") ...
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-09-07
        • 2017-07-12
        • 2017-03-01
        • 1970-01-01
        • 2023-04-04
        • 2018-12-08
        • 1970-01-01
        相关资源
        最近更新 更多