question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stepper: components inside step-content always get initialized

See original GitHub issue

Bug, feature request, or proposal:

Bug report

What is the expected behavior?

Initialize components when step is activated

What is the current behavior?

All components get initialized upon page load

What are the steps to reproduce?

Given template:

<mat-horizontal-stepper linear>
    <mat-step label="First">
        <my-first></my-first>
    </mat-step>
    <mat-step label="Second">
        <my-second></my-second>
    </mat-step>
</mat-horizontal-stepper>

Both components have a console.log() inside the constructor and ngAfterViewInit to check when they get called - they always get called upon page load.

I also tried with ng-containers around the components, “guarded” by ng-ifs - same problem!

<mat-horizontal-stepper linear>
    <mat-step label="First">
        <ng-container *ngIf="isActiveStep('First')">
            <my-first></my-first>
        </ng-container>
    </mat-step>
    <mat-step label="Second">
        <ng-container *ngIf="isActiveStep('Second')">
            <my-second></my-second>
        </ng-container>
    </mat-step>
</mat-horizontal-stepper>

What is the use-case or motivation for changing an existing behavior?

Instantiate the components when the step is active / re-instantiate when an already visited step is re-visited. This way the components could do some magic upon instantiation - and only then, when the step is currently active.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Latest of all (all RCs / GIT builds from today)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
ajamaeencommented, Jul 16, 2018

How did you fix the issue?

2reactions
MikeKovetskycommented, Mar 7, 2019

Try adding one more <ng-container> wrapper with *ngIf that checks current index.

<flow-stepper linear #flowStepper>
  <cdk-step *ngFor="let flowComponent of flowSteps; let i = index"  [label]="flowComponent.stepName"> // let i = index is added
      <ng-container *ngIf="i === flowStepper.selectedIndex"> // *ngIf is added
        <ng-container
          *ngxComponentOutlet="flowComponent.component; context: { stepperTemplate: flowStepper.stepperTemplate }">
        </ng-container>
      </ng-container>
    </cdk-step>
  </flow-stepper>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Keep the pervious step open Vertical Stepper Material-UI
Trying to implement a vertical stepper and keep the previous step open when I move the next one. I tried to use expanded...
Read more >
Stepper | Angular Material
Stream that emits whenever the labels here are changed. Use this to notify components if the labels have changed after initialization. completedLabel: string....
Read more >
React & Material UI #29: Stepper - YouTube
In this video we go over- What is a Material UI Stepper ? ... types of MUI Steppers - The props and sub...
Read more >
React Stepper component - Material UI
Steppers convey progress through numbered steps. It provides a wizard-like workflow. Steppers display progress through a sequence of logical and numbered steps.
Read more >
Mashy Teaches WebApp/Website Development with ...
It was only 2 days ago when I requested you to always start a new thread for your ... Each step content in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found