Open In App

<mat-label> in Angular Material

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-label is similar to labels which we use in normal HTML forms. But the advantage with mat-label is that it has pre-defined CSS style classes and animations defined in it.

Installation syntax:



ng add @angular/material

Approach:

Project Structure: It will look like the following.



Code Implementation:

app.module.ts:




import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { MatFormFieldModule } from '@angular/material/form-field'
  
      
import { AppComponent } from './app.component'
import { BrowserAnimationsModule } from 
    '@angular/platform-browser/animations';
  
  
@NgModule({ 
  imports: 
  [ BrowserModule, 
    FormsModule, 
    MatFormFieldModule,
    BrowserAnimationsModule], 
  declarations: [ AppComponent ], 
  bootstrap: [ AppComponent ] 
}) 
export class AppModule { }

app.component.html:




<mat-form-field appearance="legacy">
    <mat-label>Mat Label Example</mat-label>
    <input matInput placeholder="Placeholder">
</mat-form-field>

Output:
 


Article Tags :