Typescript或Angular中使用第三方库
当我们写Typescript或Angular时,有时会使用到第三方的库,例如jQuery或Bootstrap等。以jquery为例,下面就介绍一下如何进行安装。
1、安装第三方依赖
使用命令行工具,在需要用到第三方库的项目下
npm install jquery--save
2、将库引入到项目中
如果是在Angular中需要用到jquery,还需要在angular-cli.json中的apps项下配置scripts
"scripts": [
"../node_modules/jquery/dist/jquery.js"
]
如果不只是在typescript中则不需要这一步
3、安装类型描述文件
为了让typescript认出jquery,还需要安装jquery的类型描述文件
npm install @types/jquery --save-dev
这样就可以咋我们的项目中使用jquery啦~