Skip to content
Related Articles

Related Articles

<mat-list> in Angular Material

View Discussion
Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 22 Feb, 2021
View Discussion
Improve Article
Save Article

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-list> tag is used to display the list of items or records.

Installation syntax:

ng add @angular/material

Approach:

  • First, install the angular material using the above-mentioned command.
  • After completing the installation, Import ‘MatListModule’ from ‘@angular/material/list’ in the app.module.ts file.
  • After importing the ‘MatListModule’ we need to use <mat-list> tag.
  • Inside the <mat-list> tag we need to use <mat-list-item> tag for every item or labels.
  • We need to include role property for both <mat-list> tag and <mat-list-item>.
  • For <mat-list> we need to assign the role property with “list” string and for <mat-list-item> we need to assign the role property with “listitem” string value.
  • Once done with the above steps then serve or start the project.

Code Implementation:
app.module.ts:

Javascript




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

app.component.html:

HTML




<mat-list role="list">
  <mat-list-item role="listitem">HTML</mat-list-item>
  <mat-list-item role="listitem">CSS</mat-list-item>
  <mat-list-item role="listitem">Javascript</mat-list-item>
</mat-list>

Output:
 

 

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!