Home >>Ngx Bootstrap Tutorial >Ngx Bootstrap Collapse
The ngx-bootstrap Collapse directive enables you to show/hide content in a container.
selector
Inputs
Outputs
Methods
As we are going to use collapse, to use CollapseModule, we have to update app.module.ts used in the ngx-bootstrap Carousel chapter.
In order to use the CollapseModule, update app.module.ts.
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'; 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 { }
Update test.component.html to use the Collapse.
test.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>
Update test.component.ts for corresponding variables and methods.
test.component.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 { } }
Run the following command to start the angular server.
ng serve