I am creating custom stepper using CDKStepper in angular 7,
I am using
<cdk-step>
<ng-template cdkStepLabel>Fill out your name 1</ng-template>
<p>This is any content of "Step 1"</p>
</cdk-step>
and in stepper template - for navigation, I am using
<ul class="nav nav-pills wizard-navigation-ul">
<li class="step" *ngFor="let step of steps; let i = index;" [ngClass]="{'active': selectedIndex === i}">
<a href="javascript:void()" (click)="onClick(i, step)" data-toggle="tab">{{step.stepLabel}}</a>
</li>
</ul>
and in Component.ts
onClick(index: number, step: any): void {
console.log(step); // here i want to console the title of the step clicked, in this case TEXT of this "<ng-template cdkStepLabel>Fill out your name 1</ng-template>"
this.selectedIndex = index;
}
How can I get the title that is stored in <ng-template cdkStepLabel>Fill out your name 1</ng-template>?
Came across this and had to dig into the source code for a solution.
The CdkStepLabel directive has the TemplateRef as public.
Therefore we can do the following within our CdkStepper child component:
<ng-container [ngTemplateOutlet]="selected.stepLabel.template"></ng-container>
(however you want to acces the correct step is up to you)
Hope this helps future searchers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With