Skip to content
Related Articles

Related Articles

Improve Article

<mat-select> in Angular Material

  • Last Updated : 13 Apr, 2021

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-select> tag is used to display the options in a dropdown.

Installation syntax:

ng add @angular/material

Approach:

  • First, install the angular material using the above-mentioned command.
  • After completing the installation, Import ‘MatSelectModule’ from ‘@angular/material/select’ in the app.module.ts file.
  • Then use <mat-select> tag to group all the items inside this group tag.
  • Inside the <mat-select> tag we need to use <mat-option> tag for every item.
  • We can also disable options using the disabled property.
  • 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 { MatSelectModule,MatFormFieldModule } 
    from '@angular/material'
    
import { AppComponent } from './example.component'
    
@NgModule({ 
  declarations: [AppComponent], 
  exports: [AppComponent], 
  imports: [ 
    CommonModule, 
    FormsModule, 
    MatSelectModule,
    MatFormFieldModule
  
  ], 
}) 
export class AppModule {}

app.component.html:

HTML




<mat-form-field appearance="fill">
  <mat-label>Choose a technology</mat-label>
  <mat-select>
    <mat-option value="html"> HTML </mat-option>
    <mat-option value="css" disabled>CSS (disabled)</mat-option>
    <mat-option value="js">JAVASCRIPT</mat-option>
  </mat-select>
</mat-form-field>

Output:

Reference: https://material.angular.io/components/select/overview




My Personal Notes arrow_drop_up
Recommended Articles
Page :