Angular2 CLI 的 Bootstrap4 alpha(也适用于 Angular4 CLI)
如果您使用的是 angular2 cli/angular 4 cli,请执行以下操作:
npm i bootstrap@next --save
这会将引导程序 4 添加到您的项目中。
接下来转到您的 src/style.scss 或 src/style.css 文件并在那里导入引导程序:
对于 style.css
/* You can add global styles to this file, and also import other style files */
@import "../node_modules/bootstrap/dist/css/bootstrap.min.css";
对于 style.scss
/* You can add global styles to this file, and also import other style files */
@import "../node_modules/bootstrap/scss/bootstrap";
如果您使用的是 scss,请确保将.angular-cli.json 中的默认样式更改为 scss:
"defaults": {
"styleExt": "scss",
"component": {}
}
引导 JS 组件
为了让 Bootstrap JS 组件正常工作,您仍然需要将 bootstrap.js 导入到 .angular-cli.json 下的 scripts (这应该会自动发生):
...
"scripts": ["../node_modules/jquery/dist/jquery.js",
"../node_modules/tether/dist/js/tether.js",
"../node_modules/bootstrap/dist/js/bootstrap.js"],
...
2017/09/13 更新: Boostrap 4 Beta 现在使用 popper.js 而不是 tether.js。因此,根据您使用的版本,在脚本中导入 tether.js (alpha) 或 popper.js (beta)。 感谢@MinorThreat 的提醒