You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Angular(v15)中常规使用Bootstrap(v5)?样式失效求解

Angular中集成Bootstrap样式的最佳实践疑问

按照ng-bootstrap官方文档,我执行了以下命令配置Angular项目:

ng new my-ng-bootstrap-app # 创建Angular应用,选择路由和SCSS选项
ng add @ng-bootstrap/ng-bootstrap # 添加ng-bootstrap
ng generate component my-flex # 创建测试组件验证Bootstrap弹性布局
ng serve # 启动Angular服务

配置完成后,Bootstrap组件可以正常使用,但常规样式(如按钮的btn btn-primary类)不生效,示例代码如下:

<button type="button" class="btn btn-primary">
  My Button
</button>

目前我通过在app.component.html中引入CDN链接的方式让样式生效:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

请问在Angular应用中集成Bootstrap样式的最佳方式是什么?是否应该使用npm install bootstrap安装?


内容的提问来源于stack exchange,提问作者JimmyTheCode

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 08:01:55