将jQuery插件添加到Angular 2项目 [英] Adding a Jquery Plugin to an Angular 2 project
问题描述
我正在尝试将此 Jquery插件添加到我的Angular2项目中.
I am trying to add this Jquery plugin to my Angular2 project.
我已经在index.html
中将文件添加到了"src/assets"
中,我已经添加了<script src="assets/jquery.twentywenty.js"></script>
和declare var twentytwenty: any;
I have added the files to "src/assets"
also in index.html
I've added <script src="assets/jquery.twentywenty.js"></script>
and declare var twentytwenty: any;
我得到
jquery.twentytwenty.js:152未捕获的ReferenceError:jQuery不是 定义于jquery.twentytwenty.js:152
jquery.twentytwenty.js:152 Uncaught ReferenceError: jQuery is not defined at jquery.twentytwenty.js:152
还
TypeError:无法读取未定义的属性'twentytwenty'
TypeError: Cannot read property 'twentytwenty' of undefined
我在这里想念什么?
推荐答案
我通常会在我的项目中使用以下步骤来使用jquery
插件;也许有帮助.
I normally apply below steps for using jquery
plugins in my projects; maybe helpful.
1-在angular-cli.json
(scripts
部分)中添加jquery
和plugin
文件路径.
1 - Adding jquery
and plugin
files path in angular-cli.json
(scripts
section).
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"assets/vendor/plugin/jquery.plugin.js"
]
2-在组件中声明jquery
变量.
2 - Declaring jquery
variable in component.
declare let $: any;
3-使用插件语法.
(<any>$('#theId')).plugin();
这篇关于将jQuery插件添加到Angular 2项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!