角2不会导入CSS引导
直接从https://angular.io/docs/ts/latest/guide/forms.html角2不会导入CSS引导
让我们添加的样式表。
打开应用程序根文件夹一个终端窗口和输入命令:
NPM安装引导--save
打开index.html并添加以下连结的头部。
链路的rel = “样式表的” href = “node_modules /引导/ DIST/CSS/bootstrap.min.css”>
然而,我不断收到404
GET http://localhost:4200/node_modules/bootstrap/dist/css/bootstrap.min.css
它的作品,当我添加在线地址的脚本,但为什么角无法找到我的文件的路径?
当index.html
与node_modules
位于同一目录时,它正在工作。
要添加引导角CLI把
'bootstrap/dist/**/*.+(js|css.map|css|eot|svg|ttf|woff|woff2)'
在angular-cli-build.js
和运行ng build
谢谢!这就是诀窍:) –
您正在使用的构建角度CLI因此你需要在更新vendorNpmFiles
复制引导到供应商目录angularcli-build.js
bootstrap/**/*.*
现在您需要更新的index.html的链接,从销售商
< link rel="stylesheet" href="vendor/bootstrap/dist/css/bootstrap.min.css">
挑CSS如果使用角-CLI的过渡的WebPack后,添加
"../node_modules/bootstrap/dist/css/bootstrap.css"
到styles
阵列中angular-cli.json
像:
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.css"
],
如果您还使用bootstrap javascript,请将这些文件添加到scripts
阵列中。
建议将Bootstrap CSS应用于应用[0] .styles; E.I. “样式”:[ “../node_modules/bootstrap/dist/css/bootstrap.css”, “styles.css” ],参见https://www.npmjs.com/package/angular-cli –
@ MartinW将它添加到angular-cli.json或仅将其导入sass/scss文件(如果使用的话)之间有什么区别? – Todilo
不知道,为什么没有人赞成这个?这是最简单的方法。但我确实必须重做“ng serve”才能获得更改。 – Plankton
您可以检查是否存在的CSS在文件系统上的那个位置。你使用角度cli来建立?如果是,那么您需要将其复制到供应商并调整路径 –
是的,该文件在那里。通过添加到供应商你的意思是vendorNpmFiles?我在那里添加了这行'bootstrap/**/*',它仍然不起作用。 –
是的,现在检查文件是否在dist/vendor中。如果是,那就改链接链接rel =“stylesheet”href =“vendor/bootstrap/dist/css/bootstrap.min.css”> –