我使用 Angular 2 迈出了第一步,特别是我使用 Angular-cli 官方工具来创建新项目。
我以这种方式创建了一个新项目
ng new [my-project-name]
该项目已正确创建。
之后我想安装 bootstrap 4,并按照 angular-cli 页面中的官方指南进行操作。
我使用 npm 安装 bootstrap:
npm install bootstrap@next
我在 angular-cli.json 中添加了这一行:
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/tether/dist/js/tether.js",
"../node_modules/bootstrap/dist/js/bootstrap.js"
],
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.css"
],
在应用程序对象中。
当我构建应用程序并在服务器中运行它时:ng serve
我在index.html 中没有找到bootstrap css 和javascript 的参考。
我不明白该文件的导入是自动添加到我的index.html 中还是需要手动添加。
当您将脚本和样式条目添加到 angular.cli.json 文件时,它们将被添加到全局范围。具体来说,它们被添加到scripts.bundle.js和styles.bundle.js中。无需将它们添加到index.html。停止并重新启动 ng 服务后,您应该可以正常使用了。为了更好地衡量,我在更改 angular.cli.json 后运行了 npm 重建。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)