如何在 Angular 项目中使用 Bootstrap? [英] How to use Bootstrap in an Angular project?
本文介绍了如何在 Angular 项目中使用 Bootstrap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在启动我的第一个 Angular 应用程序,我的基本设置已经完成.
I am starting my first Angular application and my basic setup is done.
如何将 Bootstrap 添加到我的应用程序中?
How can I add Bootstrap to my application?
如果你能提供一个例子,那将是一个很大的帮助.
If you can provide an example then it would be a great help.
推荐答案
如果您使用 Angular-CLI 生成新项目,还有另一种方法可以在 Angular 2/中使用引导程序访问4.
Provided you use the Angular-CLI to generate new projects, there's another way to make bootstrap accessible in Angular 2/4.
- 通过命令行界面导航到项目文件夹.然后使用 npm 安装引导程序:
$ npm install --save bootstrap
.--save
选项将使引导程序出现在依赖项中. - 编辑 .angular-cli.json 文件,该文件用于配置您的项目.它在项目目录中.添加对
"styles"
数组的引用.引用必须是使用 npm 下载的引导程序文件的相对路径.就我而言,它是:"../node_modules/bootstrap/dist/css/bootstrap.min.css",
- Via command line interface navigate to the project folder. Then use npm to install bootstrap:
$ npm install --save bootstrap
. The--save
option will make bootstrap appear in the dependencies. - Edit the .angular-cli.json file, which configures your project. It's inside the project directory. Add a reference to the
"styles"
array. The reference has to be the relative path to the bootstrap file downloaded with npm. In my case it's:"../node_modules/bootstrap/dist/css/bootstrap.min.css",
我的例子.angular-cli.json:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "bootstrap-test"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json"
},
{
"project": "src/tsconfig.spec.json"
},
{
"project": "e2e/tsconfig.e2e.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}
现在引导程序应该是您默认设置的一部分.
Now bootstrap should be part of your default settings.
这篇关于如何在 Angular 项目中使用 Bootstrap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文