Angular 2不导入Bootstrap css

Dav*_*oal 7 twitter-bootstrap angular

直接来自https://angular.io/docs/ts/latest/guide/forms.html

我们来添加样式表.

在应用程序根文件夹中打开终端窗口并输入命令:

npm install bootstrap --save

打开index.html并将以下链接添加到头部.

link rel ="stylesheet"href ="node_modules/bootstrap/dist/css/bootstrap.min.css">

但是,我一直得到404

GET http:// localhost:4200/node_modules/bootstrap/dist/css/bootstrap.min.css

它在我添加带有在线地址的脚本时有效,但为什么angular无法找到我文件的路径?

Fra*_*yen 20

如果您正在使用angular-cli,则可以转到root/styles.css并添加此行

@import "../node_modules/bootstrap/dist/css/bootstrap.min.css";
Run Code Online (Sandbox Code Playgroud)

或者去.angular-cli.json修改styles

"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
]
Run Code Online (Sandbox Code Playgroud)


KB_*_*KB_ 6

当index.html它在同一目录下时它正在工作node_modules.

从angular-CLI put添加bootstrap

'bootstrap/dist/**/*.+(js|css.map|css|eot|svg|ttf|woff|woff2)'

在angular-cli-build.js和运行ng build