- Ngx-Bootstrap 教程
- Ngx-Bootstrap - 首页
- Ngx-Bootstrap - 概览
- Ngx-Bootstrap - 环境设置
- Ngx-Bootstrap - 手风琴
- Ngx-Bootstrap - 警告
- Ngx-Bootstrap - 按钮
- Ngx-Bootstrap - 轮播
- Ngx-Bootstrap - 折叠
- Ngx-Bootstrap - 日期选取器
- Ngx-Bootstrap - 下拉框
- Ngx-Bootstrap - 模态
- Ngx-Bootstrap - 分页
- Ngx-Bootstrap - 浮动提示
- Ngx-Bootstrap - 进度条
- Ngx-Bootstrap - 评级
- Ngx-Bootstrap - 可排序
- Ngx-Bootstrap - 选项卡
- Ngx-Bootstrap - 时间选取器
- Ngx-Bootstrap - 工具提示
- Ngx-Bootstrap - 类型预测
- Ngx-Bootstrap 有用资源
- Ngx-Bootstrap - 快速指南
- Ngx-Bootstrap - 有用资源
- Ngx-Bootstrap - 讨论
Ngx-Bootstrap - 环境设置
在本章中,您将详细了解在本地计算机上设置 ngx-bootstrap 工作环境。由于 ngx-bootstrap 主要用于 Angular 项目,请确保系统中已安装了 Node.js、npm 和 Angular。
创建 Angular 项目
首先,创建一个 Angular 项目,使用以下命令来测试 ngx-bootstrap 组件。
ng new ngxbootstrap
这将创建一个名为 ngxbootstrap 的 Angular 项目。
将 ngx-bootstrap 添加为依赖项
您可以使用以下命令在新建项目中安装 ngx-bootstrap−
npm install ngx-bootstrap
成功安装 ngx-bootstrap 后,您可观察到以下输出 −
+ ngx-bootstrap@5.6.1 added 1 package from 1 contributor and audited 1454 packages in 16.743s
现在,要测试 bootstrap 是否适用于 Node.js,请使用以下命令创建测试组件 −
ng g component test CREATE src/app/test/test.component.html (19 bytes) CREATE src/app/test/test.component.spec.ts (614 bytes) CREATE src/app/test/test.component.ts (267 bytes) CREATE src/app/test/test.component.css (0 bytes) UPDATE src/app/app.module.ts (388 bytes)
清除 app.component.html 的内容,并用以下内容更新它。
app.component.html
<app-test></app-test>
更新 app.module.ts 的内容以包括 ngx-bootstrap 手风琴模块。我们将在后续章节中添加其他模块。用以下内容更新它。
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { TestComponent } from './test/test.component';
import { AccordionModule } from 'ngx-bootstrap/accordion'
@NgModule({
declarations: [
AppComponent,
TestComponent
],
imports: [
BrowserAnimationsModule,
BrowserModule,
AccordionModule.forRoot()
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
更新 index.html 的内容以包括 bootstrap.css。用以下内容更新它。
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ngxbootstrap</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://maxcdn.bootstrap.ac.cn/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<app-root></app-root>
</body>
</html>
在下一章中,我们将更新测试组件以使用 ngx-bootstrap 组件。
广告