Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

<mat-label> in Angular Material

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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:

  • First, install the angular material using the above-mentioned command.
  • After completing the installation, Import ‘MatFormFieldModule’ from ‘@angular/material/form-field’ in the app.module.ts file.
  • Now we need to use <mat-label> tag with respective label name inside the <mat-form-field> tag.
  • Below is an example on how to use <mat-label> tag inside <mat-form-field>
  • Once done with the above steps then serve or start the project.

Project Structure: It will look like the following.

Code Implementation:

app.module.ts:

Javascript




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:

HTML




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

Output:
 


My Personal Notes arrow_drop_up
Last Updated : 05 Feb, 2021
Like Article
Save Article
Similar Reads
Related Tutorials