Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch between vertical and horizontal stepper material

How to switch between mat-vertical-stepper and mat-horizontal-stepper from angular component with same stepper steps?

like image 423
Ashish Gurjar Avatar asked Dec 30 '17 09:12

Ashish Gurjar


People also ask

How many types of steppers are there?

There are three main types of stepper motors: Permanent magnet stepper. Variable reluctance stepper. Hybrid synchronous stepper.

What is mat step?

Overview for stepper. Angular Material's stepper provides a wizard-like workflow by dividing content into logical steps. Material stepper builds on the foundation of the CDK stepper that is responsible for the logic that drives a stepped workflow. Material stepper extends the CDK stepper and has Material Design styling ...

How do I change the color of my mat stepper icon?

There does not seem to be option to change color of mat stepper icon, you can use this css as workaround. Custom theme class can be used across application,just wrapp any material component and use color attribute primary,accent or warn as defined in class.


1 Answers

to avoid rewriting identical html content, do like this. Create the template and give them a reference using a #hashtag. then you can instert them using ng-container *ngTemplateOutlet="hashtag"></ng-container>.

here is an example of making a responsive stepepr, the angular material way.

<ng-template #stepOne>   <div>step one</div> </ng-template>  <ng-template #stepTwo>   <div>step two</div> </ng-template>  <ng-template #stepThree>   <div>step three</div> </ng-template>  <ng-template #stepFour>   <div>step four</div> </ng-template>  <ng-template [ngIf]="smallScreen" [ngIfElse]="bigScreen">   <mat-vertical-stepper linear #stepper >     <mat-step>       <ng-container *ngTemplateOutlet="stepOne"></ng-container>     </mat-step>     <mat-step>       <ng-container *ngTemplateOutlet="stepTwo"></ng-container>     </mat-step>     <mat-step>       <ng-container *ngTemplateOutlet="stepThree"></ng-container>     </mat-step>     <mat-step>       <ng-container *ngTemplateOutlet="stepFour"></ng-container>     </mat-step>   </mat-vertical-stepper> </ng-template>  <ng-template #bigScreen>   <mat-horizontal-stepper linear #stepper >     <mat-step>       <ng-container *ngTemplateOutlet="stepOne"></ng-container>     </mat-step>     <mat-step >       <ng-container *ngTemplateOutlet="stepTwo"></ng-container>     </mat-step>     <mat-step>       <ng-container *ngTemplateOutlet="stepThree"></ng-container>     </mat-step>     <mat-step>       <ng-container *ngTemplateOutlet="stepFour"></ng-container>     </mat-step>   </mat-horizontal-stepper> </ng-template> 

You can use the angular cdk layout to track screen size like this.

import { Component } from '@angular/core'; import {BreakpointObserver, Breakpoints} from '@angular/cdk/layout';  @Component({   selector: 'app-responsive-stepper',   templateUrl: './responsive-stepper.component.html',   styleUrls: ['./responsive-stepper.component.scss'] }) export class ResponsiveStepperComponent implements OnInit {      smallScreen: boolean;      constructor(        private breakpointObserver: BreakpointObserver       ) {         breakpointObserver.observe([           Breakpoints.XSmall,           Breakpoints.Small         ]).subscribe(result => {           this.smallScreen = result.matches;       });      } } 
like image 72
Joey Gough Avatar answered Oct 11 '22 16:10

Joey Gough