angular

angular 使用 Bootstrap

2018-06-12  本文已影响53人  王义杰

Include Bootstrap

包括 Bootstrap

Bootstrap is a popular CSS framework which can be used within an Angular project.
This guide will walk you through adding bootstrap to your Angular CLI project and configuring it to use bootstrap.
Bootstrap 是一个流行的CSS框架,可以在Angular项目中使用。本指南将引导您为Angular CLI项目添加引导程序并将其配置为使用引导程序。

Using CSS

使用CSS

Getting Started

开始

Create a new project and navigate into the project
创建一个新项目并导航到项目中

ng new my-app
cd my-app

Installing Bootstrap

安装 Bootstrap

With the new project created and ready you will next need to install bootstrap to your project as a dependency.
Using the --save option the dependency will be saved in package.json
随着新项目的创建和准备,接下来需要将引导程序作为依赖项安装到项目中。使用--save选项,依赖项将被保存在package.json中

npm install bootstrap --save

Configuring Project

配置项目

Now that the project is set up it must be configured to include the bootstrap CSS.
现在该项目已经建立,它必须配置为包含引导CSS。

Note: When you make changes to angular.json you will need to re-start ng serve to pick up configuration changes.
注意:当您对 angular.json 进行更改时,您将需要重新启动服务来获取配置更改。

Testing Project

测试项目

Open app.component.html and add the following markup:
打开 app.component.html 添加下列标记:

<button class="btn btn-primary">Test Button</button>

With the application configured, run ng serve to run your application in develop mode.
In your browser navigate to the application localhost:4200.
Verify the bootstrap styled button appears.
在配置应用程序后,运行 ng serve 以开发模式运行您的应用程序。在浏览器中导航到应用程序 localhost:4200。验证引导样式按钮出现。

Using SASS

使用 SASS

Getting Started

开始

Create a new project and navigate into the project
创建一个新项目并导航到项目中

ng new my-app --style=scss
cd my-app

Installing Bootstrap

安装 Bootstrap

npm install bootstrap --save

Configuring Project

配置项目

Create an empty file _variables.scss in src/.
src/ 中创建一个文件 _variables.scss

If you are using bootstrap-sass, add the following to _variables.scss:
如果你使用 bootstrap-sass, 将下面的内容添加到 _variables.scss:

$icon-font-path: '../node_modules/bootstrap-sass/assets/fonts/bootstrap/';

in styles.scss add the following:
styles.scss 中添加下列内容:

@import 'variables';
@import '../node_modules/bootstrap/scss/bootstrap';

Testing Project

测试项目

Open app.component.html and add the following markup:
打开 app.component.html 添加下列标记:

<button class="btn btn-primary">Test Button</button>

With the application configured, run ng serve to run your application in develop mode.
In your browser navigate to the application localhost:4200.
Verify the bootstrap styled button appears.
To ensure your variables are used open _variables.scss and add the following:
配置应用程序后, 运行 ng serve 启动你的应用程序在开发模式。 在浏览器中导航到你的应用程序 localhost:4200. 验证引导样式按钮出现. 要确保您的变量使用打开_variables.scss并添加以下内容

$primary: red;

Return the browser to see the font color changed.
返回浏览器查看更改的字体颜色。

上一篇下一篇

猜你喜欢

热点阅读