将jQuery插件添加到Angular 2项目 [英] Adding a Jquery Plugin to an Angular 2 project

查看:97
本文介绍了将jQuery插件添加到Angular 2项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将此 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部分)中添加jqueryplugin文件路径.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆