全局库安装
2018-06-11 本文已影响15人
王义杰
Global Library Installation
全局库安装
Some javascript libraries need to be added to the global scope and loaded as if
they were in a script tag.
We can do this using the scripts
and styles
options of the build target in angular.json
.
一些JavaScript库需要被添加到全局范围并加载,就好像它们在脚本标签中一样,我们可以使用angular.json中构建目标的脚本和样式选项来完成此操作。
As an example, to use Bootstrap 4
this is what you need to do:
例如,要使用Bootstrap 4,您需要执行以下操作:
First install Bootstrap from npm
:
首先从 npm
安装Bootstrap:
npm install jquery --save
npm install popper.js --save
npm install bootstrap --save
Then add the needed script files to scripts
:
然后将所需的脚本文件添加到 scripts
中:
"scripts": [
"node_modules/jquery/dist/jquery.slim.js",
"node_modules/popper.js/dist/umd/popper.js",
"node_modules/bootstrap/dist/js/bootstrap.js"
],
Finally add the Bootstrap CSS to the styles
array:
最后,将Bootstrap CSS添加到 styles
数组中:
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.css",
"src/styles.css"
],
Restart ng serve
if you're running it, and Bootstrap 4 should be working on your app.
如果您正在运行它,请重新启动服务,并且Bootstrap 4应该在您的应用程序上运行。