在angular里面使用jQuery和bootstrap

来源:互联网 发布:javascript插件dll 编辑:程序博客网 时间:2024/06/10 13:33

第一步:

1.在你的项目目录下面:npm install jquery --save

--save是将jQuery加入package.json里面

2.在项目目录下面npm install bootstrap --save

安装完成后:

"bootstrap": "^3.3.7","core-js": "^2.4.1","jquery": "^3.2.1",

第二步:

在angular/cli里面将他们加到项目里面:

"styles": [  "styles.css",  "../node_modules/bootstrap/dist/css/bootstrap.css"],"scripts": [ "../node_modules/jquery/dist/jquery.js", "../node_modules/bootstrap/dist/js/bootstrap.js" ],


第三步:

安装类型定义文件,因为jQuery和bootstrap是js文件angular用的是typescript,无法编译,必须要安装他们各自对用的类型对应文件

1.npm install @types/jquery --save -dev

2.npm install @types/bootstrap  --save -dev

第四步:

将jquery放入assets文件夹

在index.html里面引入相应js


第五步:

在component里面声明,在任何拥戴的地方使用都需要声明


第六步测试是否可以用了

ng g component  xx生成叫xx的组件



请使用手机"扫一扫"x
原创粉丝点击