Skip to main content

angular material - Expansion Panel expandedChange event

app.component.ts

import { Component } from '@angular/core';
import { MatExpansionPanel } from '@angular/material/expansion';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})


export class AppComponent {
  message: string = "";
  
  onExpandedChange(panel:MatExpansionPanel){
    this.message = "Expansion Panel " 
      + (panel.expanded? 'Expanded' : 'Collapsed');
  }
}
app.component.html

<h2 style="padding-top:25px; padding-bottom:25px;">
  Angular Material - How to use 
    Expansion Panel expandedChange event
</h2>


<h3>Event: {{message}}</h3>

<mat-expansion-panel 
  #panel
  (expandedChange)="onExpandedChange(panel)">
    <mat-expansion-panel-header>
      <mat-panel-title>Bash</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