Open In App

Angular ngx Bootstrap Collapse Component

Angular ngx bootstrap is a bootstrap framework used with angular to create components with great styling and this framework is very easy to use and is used to make responsive websites.

In this article, we will learn how to use collapse in angular ngx bootstrap. Collapse is used to make a button that will collapse by clicking on it.



Installation syntax:

npm install ngx-bootstrap --save 


 

Approach:

Example 1:




<!doctype html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <base href="/">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1">
    <link href=
        rel="stylesheet">
  
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href=
        rel="stylesheet">
    <link href=
        rel="stylesheet">
</head>
  
<body class="mat-typography">
    <app-root></app-root>
</body>
  
</html>




<button type="button" class="btn btn-success" 
    (click)="gfg = !gfg" aria-controls="geeks">
    Click to collapse!
</button>
<hr>
<div id="geeks" [collapse]="gfg">
    <div class="well well-lg card 
        card-block card-header">
        GeeksforGeeks
    </div>
</div>
<br />
<button type="button" class="btn btn-success" 
    (click)="gfg1 = !gfg1" aria-controls="geeks1">
    Click to collapse!
</button>
<hr>
<div id="geeks1" [collapse]="gfg1">
    <div class="well well-lg card 
        card-block card-header">
        GeeksforGeeks
    </div>
</div>




import { NgModule } from '@angular/core';
  
// Importing forms module
import {
    FormsModule,
    ReactiveFormsModule
} from '@angular/forms';
import { BrowserModule }
    from '@angular/platform-browser';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { CollapseModule } from 'ngx-bootstrap/collapse';
  
  
import { AppComponent } from './app.component';
  
@NgModule({
    bootstrap: [
        AppComponent
    ],
    declarations: [
        AppComponent
    ],
    imports: [
        FormsModule,
        BrowserModule,
        BrowserAnimationsModule,
        ReactiveFormsModule,
        CollapseModule.forRoot()
    ]
})
export class AppModule { }

Output:

Reference: https://valor-software.com/ngx-bootstrap/#/collapse


Article Tags :