首页 技术 正文
技术 2022年11月16日
0 收藏 856 点赞 3,936 浏览 1083 个字

集成步骤:

1、安装jquery极其扩展插件库ts定义文件

npm install jquery --save
npm install --save-dev @types/jquery
npm install datatables.net --save
npm install @types/datatables.net --save-dev

2、页面加载jquery和扩展插件:

"apps": [{
...
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/datatables.net/js/jquery.dataTables.js",
],
...
}]

3、把扩展插件module加入到tsconfig.app.json的types配置。

"types": [
"echarts",
"datatables.net",
"bootstrap",
"admin-lte"
]

4、调用扩展插件的方法:

$("selector").pluginMethod();   

5、运行ng serve:

ng serve -o

这个里面有个问题,就是我们不是直接去尝试调用jquery plugin,jquery接口的ts定义扩展是通过plugin的d.ts文件去扩展的,我们调用jquery本身,在编译时,编译器自动去寻找相关的plugin定义并扩展原始jquery的接口。搞清楚这一点,很多基于jQuery选择器函数的JS库集成就方便多了。

最后分析几个错误:

1、编译的时候出现

Property 'DataTable' does not exist on type 'JQuery<HTMLElement>'.

是因为定义DataTable的datatables.net库没有放进types设置,导致编译时找不到这个方法定义。

2、Lint的时候出现错误:

Error:(5, 22) TS2306:File '/Users/denghui/ng/ord/node_modules/@types/datatables.net/index.d.ts' is not a module.

是因为JQuery和他的插件都是全局库,一是没有必要用import语法导入,二是它的types定义里面也没有module定义,所以import时出现这个错误,解决方法是全局库极其插件无需导入,直接使用jQuery释放的$接口即可。

参考资料:https://stackoverflow.com/questions/43934727/how-to-use-jquery-plugin-with-angular-4

上一篇: geth常用指令
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,496
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,909
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,743
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,496
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,134
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298