在 Angular 中安装 Bootstrap

Rana Hasnain Khan 2022年4月20日
在 Angular 中安装 Bootstrap

我们将介绍如何在 Angular 中安装和使用 Bootstrap。

在 Angular 中安装 Bootstrap

Bootstrap 是一个 CSS 框架,用于快速设计一个响应式和移动友好的网站。它是广泛使用的最流行的框架。

我们还可以按照这些简单易行的步骤在 Angular 应用程序中安装 Bootstrap。要创建一个新的 Angular 应用程序,我们将在终端中执行以下命令。

# Terminal
ng new my-app
cd my-app

上面的命令创建了一个新的 Angular 项目并将我们带到 my-app 项目目录。

现在我们需要在 Angular 项目中安装 Bootstrap,为此,我们需要转到终端并运行以下命令。

# cli
npm install bootstrap --save

该命令将在我们的 Angular 项目中安装 Bootstrap。但是,如果你在项目中使用 SASS,请安装 bootstrap-sass

# cli
npm install bootstrap-sass --save

安装 Bootstrap 后,它将保存在节点模块中,现在我们只需要使用以下导入命令在要使用 Bootstrap 的任何地方导入 Bootstrap CSS。

# angular
@import '~bootstrap/dist/css/bootstrap.css';

或者,如果你使用的是 SASS

# angular
$icon-font-path: '~bootstrap-sass/assets/fonts/bootstrap/';
@import '~bootstrap-sass/assets/stylesheets/bootstrap';

我们可以轻松地在我们的 Angular 应用程序中安装 Bootstrap,并按照这些简单的步骤使用 Bootstrap 类使其具有响应性和移动友好性。

Rana Hasnain Khan avatar Rana Hasnain Khan avatar

Rana is a computer science graduate passionate about helping people to build and diagnose scalable web application problems and problems developers face across the full-stack.

LinkedIn

相关文章 - Angular Bootstrap