将Jquery插件添加到Angular 2项目

时间:2018-02-13 13:35:49

标签: jquery angular

我正在尝试将此Jquery plugin添加到我的Angular2项目中。

我已将"src/assets"文件添加到index.html我已添加<script src="assets/jquery.twentywenty.js"></script>declare var twentytwenty: any;

我正在

  

jquery.twentytwenty.js:152 Uncaught ReferenceError:jQuery不是       在jquery.twentytwenty.js:152

中定义

  

TypeError:无法读取未定义的属性“二十二”

我在这里缺少什么?

1 个答案:

答案 0 :(得分:2)

我通常会在我的项目中使用以下步骤来使用jquery插件;也许有帮助。

1 - 在jqueryplugin部分)中添加angular-cli.jsonscripts个文件路径。

  "scripts": [
    "../node_modules/jquery/dist/jquery.js",
    "assets/vendor/plugin/jquery.plugin.js"
  ]

2 - 在组件中声明jquery变量。

declare let $: any;

3 - 使用插件语法。

(<any>$('#theId')).plugin();