Angular Bootstrap collapse

Bootstrap collapse plugin allows you to toggle content on your pages with a bit of JavaScript and some classes. A flexible plugin that utilizes a handful of classes for easy toggle behavior.


Basic examples

Add (click)="test.toggle()" mdbWavesEffect to the button tag.

Place the collapse content <div> in the parent <div> and add [collapse]="isCollapsed" #test="bs-collapse" inside.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.


<button mdbBtn color="primary" class="waves-light" type="button" (click)="test.toggle()" mdbWavesEffect>
    Toggle collapse
</button>

<div class="" mdbCollapse #test="bs-collapse">
    <p>Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.</p>
</div>
        

Collapse visible after view init

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.


<button class="btn btn-primary waves-light" type="button" (click)="test.toggle()" mdbWavesEffect>
  Toggle collapse
</button>

<div class="" mdbCollapse [isCollapsed]="false" #test="bs-collapse">
  <p>Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica,
    craft beer labore wes anderson cred nesciunt sapiente ea proident.</p>
</div>
	

// For MDB Angular Free
import { CollapseDirective } from 'angular-bootstrap-md';
// For MDB Angular Pro
import { CollapseDirective } from 'ng-uikit-pro-standard';
import { Component, ViewChildren, AfterViewInit } from '@angular/core';

@Component({
  selector: 'visible-collapse',
  templateUrl: './visible-collapse.component.html',
  styleUrls: ['./visible-collapse.component.scss'],
})
export class VisibleCollapseComponent implements AfterViewInit {
  @ViewChildren(CollapseDirective) collapses: CollapseDirective[];

  ngAfterViewInit() {
    this.collapses.forEach((collapse: CollapseDirective) => {
      collapse.show();
    });
  }
}
  

Collapse events

Event Type Description
(showBsCollapse)="showBsCollapse()" This event fires immediately when the show instance method is called.
(shownBsCollapse)="shownBsCollapse()" This event is fired when a collapse element has been made visible to the user (will wait for CSS transitions to complete).
(hideBsCollapse)="hideBsCollapse()" This event is fired immediately when the hide method has been called.
(hiddenBsCollapse)="hiddenBsCollapse()" This event is fired when a collapse element has been hidden from the user (will wait for CSS transitions to complete).

<button class="btn btn-primary waves-light" type="button" (click)="test.toggle()" mdbWavesEffect>
    Toggle collapse
</button>

<div class="" mdbCollapse #test="bs-collapse" (showBsCollapse)="showBsCollapse($event)" (shownBsCollapse)="shownBsCollapse($event)" (hideBsCollapse)="hideBsCollapse($event)" (hiddenBsCollapse)="hiddenBsCollapse($event)">
    <div class="card card-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
    </div>
</div>
	

import { Component } from '@angular/core';

@Component({
  selector: 'collapse-example',
  templateUrl: 'collapse-example.html',
})

export class CollapseExampleComponent  {

    showBsCollapse(event: any) { console.log(event); }
    shownBsCollapse(event: any) { console.log(event); }
    hideBsCollapse(event: any) { console.log(event); }
    hiddenBsCollapse(event: any) { console.log(event); }
}
  

Accessibility

Be sure to add aria-expanded to the control element. This attribute explicitly defines the current state of the collapsible element to screen readers and similar assistive technologies. If the collapsible element is closed by default, it should have a value of aria-expanded="false". If you’ve set the collapsible element to be open by default using the in class, set aria-expanded="true" on the control instead. The plugin will automatically toggle this attribute based on whether or not the collapsible element has been opened or closed.

Additionally, if your control element is targeting a single collapsible element – i.e. the data-target attribute is pointing to an id selector – you may add an additional aria-controls attribute to the control element, containing the id of the collapsible element. Modern screen readers and similar assistive technologies make use of this attribute to provide users with additional shortcuts to navigate directly to the collapsible element itself.


Accordion MDB Pro component

Extend the default collapse behavior to create an accordion.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.


<!--Accordion wrapper-->
<mdb-accordion [multiple]="false" aria-multiselectable="true">
    <mdb-accordion-item  [collapsed]="false" *ngFor="let item of itemsList">
        <mdb-accordion-item-head> {{ item.title }} </mdb-accordion-item-head>
        <mdb-accordion-item-body> {{ item.description }} </mdb-accordion-item-body>
    </mdb-accordion-item>
</mdb-accordion>
<!--/.Accordion wrapper-->
	

import { Component } from '@angular/core';

@Component({
  selector: 'accordion-example',
  templateUrl: 'accordion-example.html',
})

export class AccordionExampleComponent  {

    public itemsList:Object[] = [
        {
            title: 'Collapsible Group Item #1',
            description: 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven\'t heard of them accusamus labore sustainable VHS.'
        },
         {
            title: 'Collapsible Group Item #2',
            description: 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven\'t heard of them accusamus labore sustainable VHS.'
        },
         {
            title: 'Collapsible Group Item #3',
            description: 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven\'t heard of them accusamus labore sustainable VHS.'
        }
    ]
}
  

Disabled Accordion item MDB Pro component

Disabled item via isDisabled property in Accordion.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.


<!--Accordion wrapper-->
<mdb-accordion [multiple]="true" aria-multiselectable="true">
  <mdb-accordion-item [collapsed]="false">
    <mdb-accordion-item-head> {{ itemsList[0].title }} </mdb-accordion-item-head>
    <mdb-accordion-item-body> {{ itemsList[0].description }} </mdb-accordion-item-body>
  </mdb-accordion-item>
  <mdb-accordion-item [collapsed]="false">
    <mdb-accordion-item-head [isDisabled]="true"> {{ itemsList[1].title }} </mdb-accordion-item-head>
    <mdb-accordion-item-body> {{ itemsList[1].description }} </mdb-accordion-item-body>
  </mdb-accordion-item>
  <mdb-accordion-item [collapsed]="false">
    <mdb-accordion-item-head> {{ itemsList[2].title }} </mdb-accordion-item-head>
    <mdb-accordion-item-body> {{ itemsList[2].description }} </mdb-accordion-item-body>
  </mdb-accordion-item>
</mdb-accordion>
<!--/.Accordion wrapper-->
	

import { Component } from '@angular/core';

@Component({
  selector: 'accordion-disabled',
  templateUrl: 'accordion-disabled.html',
})

export class DisabledAccordionItemComponent  {

    public itemsList:Object[] = [
        {
            title: 'Collapsible Group Item #1',
            description: 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven\'t heard of them accusamus labore sustainable VHS.'
        },
         {
            title: 'Collapsible Group Item #2',
            description: 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven\'t heard of them accusamus labore sustainable VHS.'
        },
         {
            title: 'Collapsible Group Item #3',
            description: 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven\'t heard of them accusamus labore sustainable VHS.'
        }
    ]
}
  

Accordion Options

Field name Type Default Description
multiple Boolean True This attribute enable/disable the multiple item expanded at the same time.
collapsed Boolean True This attribute enable/disable collapse from the beginning when component is rendered.
isDisabled Boolean false This attribute disable accordion item when true.

API Reference:

In order to speed up your application, you can choose to import only the modules you actually need, instead of importing the entire MDB Angular library. Remember that importing the entire library, and immediately afterwards a specific module, is bad practice, and can cause application errors.

API Reference for MDB Angular Collapse:
// For MDB Angular Pro
import { CollapseModule, WavesModule } from 'ng-uikit-pro-standard'
// For MDB Angular Pro Accordion
import { AccordionModule, WavesModule } from 'ng-uikit-pro-standard'
// For MDB Angular Free
import { CollapseModule, WavesModule } from 'angular-bootstrap-md'