At first we need to add angular material in our application. we are install angular material using below command,
ng add @angular/material
We need to import the modules for stepper line in app.module.ts :
import {MatStepperModule} from '@angular/material/stepper'; @NgModule ({ imports: [ MatStepperModule, ] }) class AppModule {}
Add below lines in app.component.ts :
import { Component } from '@angular/core'; import {FormBuilder, Validators} from '@angular/forms'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent { firstFormGroup = this._formBuilder.group({ firstCtrl: ['', Validators.required], }); secondFormGroup = this._formBuilder.group({ secondCtrl: ['', Validators.required], }); isLinear = false; constructor(private _formBuilder: FormBuilder) {} }
Also add below lines in app.component.html :
<mat-stepper class="w-25" [linear]="isLinear" #stepper> <mat-step [stepControl]="firstFormGroup"> <form [formGroup]="firstFormGroup"> <ng-template matStepLabel>Fill out your name</ng-template> <mat-form-field appearance="fill"> <mat-label>Name</mat-label> <input matInput placeholder="Last name, First name" formControlName="firstCtrl" required> </mat-form-field> <div> <button mat-button matStepperNext>Next</button> </div> </form> </mat-step> <mat-step [stepControl]="secondFormGroup" label="Fill out your address"> <form [formGroup]="secondFormGroup"> <mat-form-field appearance="fill"> <mat-label>Address</mat-label> <input matInput formControlName="secondCtrl" placeholder="Ex. 1 Main St, New York, NY" required> </mat-form-field> <div> <button mat-button matStepperPrevious>Back</button> <button mat-button matStepperNext>Next</button> </div> </form> </mat-step> <mat-step> <ng-template matStepLabel>Done</ng-template> <p>You are now done.</p> <div> <button mat-button matStepperPrevious>Back</button> <button mat-button (click)="stepper.reset()">Reset</button> </div> </mat-step> </mat-stepper>
Now, Run our application :