- Ngx-Bootstrap 教程
 - Ngx-Bootstrap - 主页
 - Ngx-Bootstrap - 概述
 - Ngx-Bootstrap - 环境设置
 - Ngx-Bootstrap - 手风琴
 - Ngx-Bootstrap - 警报
 - Ngx-Bootstrap - 按钮
 - Ngx-Bootstrap - 轮播
 - Ngx-Bootstrap - 折叠
 - Ngx-Bootstrap - DatePicker
 - Ngx-Bootstrap - 下拉菜单
 - Ngx-Bootstrap - 模态框
 - Ngx-Bootstrap - 分页
 - Ngx-Bootstrap - 弹出窗口
 - Ngx-Bootstrap - 进度条
 - Ngx-Bootstrap - 评级
 - Ngx-Bootstrap - 可排序
 - Ngx-Bootstrap - 选项卡
 - Ngx-Bootstrap - 时间选择器
 - Ngx-Bootstrap - 工具提示
 - Ngx-Bootstrap - Typeahead
 - Ngx-Bootstrap 有用资源
 - Ngx-Bootstrap - 快速指南
 - Ngx-Bootstrap - 有用的资源
 - Ngx-Bootstrap - 讨论
 
Ngx-Bootstrap - 折叠
ngx-bootstrap Collapse 指令有助于显示/隐藏容器内容。
崩溃指令
选择器
[坍塌]
输入
折叠- 布尔值,指示内容可见性的标志(显示或隐藏)
显示- 字符串
isAnimated - 布尔值,打开/关闭动画。默认值:假
输出
折叠- 内容折叠后立即触发此事件
折叠- 开始折叠时触发此事件
Expanded - 一旦内容可见,此事件就会触发
Expands - 当扩展开始时触发此事件
方法
toggle() - 允许手动切换内容可见性
hide - 允许手动隐藏内容
show - 允许手动显示折叠的内容
例子
由于我们要使用折叠,我们必须更新ngx-bootstrap Carousel章节中使用的 app.module.ts 以使用CollapseModule。
更新 app.module.ts 以使用 CollapseModule。
应用程序模块.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';
import { AlertModule,AlertConfig } from 'ngx-bootstrap/alert';
import { ButtonsModule } from 'ngx-bootstrap/buttons';
import { FormsModule } from '@angular/forms';
import { CarouselModule } from 'ngx-bootstrap/carousel';
import { CollapseModule } from 'ngx-bootstrap/collapse';
@NgModule({
   declarations: [
      AppComponent,
      TestComponent
   ],
   imports: [
      BrowserAnimationsModule,
      BrowserModule,
      AccordionModule,
      AlertModule,
      ButtonsModule,
      FormsModule,
      CarouselModule,
      CollapseModule
   ],
   providers: [AlertConfig],
   bootstrap: [AppComponent]
})
export class AppModule { }
更新 test.component.html 以使用 Collapse。
测试.component.html
<div>
   <div class="checkbox">
      <label><input type="checkbox" [(ngModel)]="isCollapsed">Collapse</label>
   </div>
</div>
<div [collapse]="isCollapsed" [isAnimated]="true">
   <div class="well well-lg card card-block card-header">Welcome to Tutorialspoint.</div>
</div>
更新 test.component.ts 中相应的变量和方法。
测试组件.ts
import { Component, OnInit } from '@angular/core';
@Component({
   selector: 'app-test',
   templateUrl: './test.component.html',
   styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
   isCollapsed: boolean = false;
   constructor() { }
   ngOnInit(): void {
   }
}
构建和服务
运行以下命令启动角度服务器。
ng serve
服务器启动并运行后。打开 http://localhost:4200 并验证以下输出。
选中折叠复选框,内容将被折叠。
