Open In App

<mat-expansion-panel> in Angular Material

Improve
Improve
Like Article
Like
Save
Share
Report

Introduction:
Angular Material is a UI component library that is developed by the Angular team to build design components for desktop and mobile web applications. In order to install it, we need to have angular installed in our project, once you have it you can enter the below command and can download it. <mat-expansion-panel> tag is a kind of dropdown which has collapse and expand functionalities.

Installation syntax:

ng add @angular/material

Approach:

  • First, install the angular material using the above-mentioned command.
  • After completing the installation, Import ‘MatExpansionModule’ from ‘@angular/material/expansion’ in the app.module.ts file.
  • Then use <mat-accordion> tag as a parent tag for <mat-expansion-panel> tag.
  • Inside the <mat-accordion> tag we need to use <mat-expansion-panel> tag for every item.
  • For <mat-expansion-panel> tag we have many child tags which is been explained in the below table.
  • Once done with the above steps then serve or start the project.
Tag Name Property
<mat-panel-title> It is used to display the title for the panel
<mat-panel-description> It is used to display the information regarding the panel.

Code Implementation:

app.module.ts




import { CommonModule } from '@angular/common'
import { NgModule } from '@angular/core'
import { FormsModule } from '@angular/forms'
import { MatExpansionModule } from '@angular/material'
    
import { AppComponent } from './example.component'
    
@NgModule({ 
  declarations: [AppComponent], 
  exports: [AppComponent], 
  imports: [ 
    CommonModule, 
    FormsModule, 
    MatExpansionModule
  
  ], 
}) 
export class AppModule {}


app.component.html




<mat-accordion>
  <mat-expansion-panel >
    <mat-expansion-panel-header>
      <mat-panel-title>
         GEEKSFORGEEKS      
      </mat-panel-title>
      <mat-panel-description>
        Click here to expand the panel      
      </mat-panel-description>
    </mat-expansion-panel-header>
      
<p>One stop portal to all Computer Science Subjects. </p>
  
  </mat-expansion-panel>
  
</mat-accordion>


Output:



Last Updated : 25 Feb, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads