-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(stepper): support lazy rendering of steps #12817
Comments
Yes, I need this as well for a project. I tried a number of approaches but they don't seem to be supported by the current implementation as the compiler throws errors or steps that are added later don't show up. |
Here's a nice (related) example of using |
It would be really cool if its supported out of the box |
Not sure if I am just stating the obvious, but I was able to implement lazy-loading based on @snebjorn 's approach quite easily:
Note that the condition for the first step needs to include the check for null, too. Otherwise you'll receive an ExpressionChangedAfterItHasBeenCheckedError. |
Is there any update on when feature will be available? |
@matthiaswelz I have a linear form like below. How can i implement your approach in this?
If i try to add |
Is there any update? |
I tried @matthiaswelz solution, but it still seems to be loading all 3 components. I can verify this by removing the 2nd & 3rd components and watch the load time of the first step go down from 10 seconds to 2 seconds. The components in each of my three steps are not huge, but not trivial either. |
@akvaliya A workaround that I haven't tried:
Yup, not so clean. Also: not sure if a |
You can use use to load content of steps and in routes' file, use lazy loading for loading modules in each step. template file: <mat-horizontal-stepper #stepper>
<mat-step *ngFor="let step of steps; let i=index;">
<router-outlet *ngIf="stepper.selectedIndex==i"></router-outlet>
</mat-step>
</mat-horizontal-stepper> routes.ts: const routes: Routes = [
{ path: 'step0', loadChildren: module for component 1},
]
}
]; |
@matthiaswelz "CdkStep and TemplateRef have no overlap". |
Next level of @matthiaswelz's workaround in order to get the collapse animation right: Render the previous step 225ms longer. <mat-vertical-stepper (selectionChange)="selectionChange($event)">
<mat-step #step1>
<ng-container *ngIf="renderStep('default') || renderStep(step1)">
...
</ng-container>
</mat-step>
<mat-step #step2>
<ng-container *ngIf="renderStep(step2)">
...
</ng-container>
</mat-step> private _renderStep: CdkStep[] = [];
renderStep(step: CdkStep | 'default'): boolean {
// workaround for https://github.com/angular/components/issues/12817#issuecomment-457314797
return step === 'default' ? this._renderStep.length === 0 : this._renderStep.includes(step);
}
selectionChange(event: StepperSelectionEvent) {
this._renderStep.push(event.selectedStep);
// see https://github.com/angular/components/blob/master/src/material/stepper/stepper-animations.ts
setTimeout(() => this._renderStep = [event.selectedStep], 225);
} |
Duplicate of #12339 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
feature request-ish
What is the expected behavior?
Each step in the stepper should have the option to be lazily rendered
What is the current behavior?
Currently every step is initialized when the stepper is loaded
What is the use-case or motivation for changing an existing behavior?
Inactive steps can have logic that fetches data or does some work that isn't relevant to the current step.
Currently there isn't any mention of how to achieve this in the stepper. However it can be done via
<ng-container *ngIf="condition">
, not sure if there are any side effects.The expansion panel supports lazy rendering "officially" https://material.angular.io/components/expansion/overview#lazy-rendering
Why is there a difference? If the
<ng-container>
is a perfectly fine solution why doesn't the expansion panel do it the same way? Why is there no mention of lazy rendering in the stepper doc?Which versions of Angular, Material, OS, TypeScript, browsers are affected?
The text was updated successfully, but these errors were encountered: