Skip to main content

angular material - How to toggle Expansion Panel expanded state

app.component.html

<h2 style="padding-top:25px; padding-bottom:25px;">
  Angular Material - 
    How to toggle Expansion Panel expanded state
</h2>


<h3>
  Expansion Panel is now :
  {{panel.expanded? 'Expanded' : 'Collapsed'}}
</h3>

<button 
  mat-raised-button 
  (click)="panel.toggle()"
  color="primary">
    Toggle Expanded State
</button>

<br/><br/>

<mat-expansion-panel #panel>
  <mat-expansion-panel-header>
    <mat-panel-title>Spring</mat-panel-title>
  </mat-expansion-panel-header>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  Integer vitae semper massa. Donec maximus, dui nec
  dignissim blandit, ante odio varius ex,
  nec volutpat erat justo ac magna.
</mat-expansion-panel>
app.module.ts [import]

import {MatExpansionModule} from '@angular/material/expansion'
More Angular tutorials