我正在使用angular 7中的CDKStepper创建自定义步进器,
我正在使用
<cdk-step>
<ng-template cdkStepLabel>Fill out your name 1</ng-template>
<p>This is any content of "Step 1"</p>
</cdk-step>在stepper模板中-用于导航,我使用
<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>在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;
}如何获取存储在<ng-template cdkStepLabel>Fill out your name 1</ng-template>中的标题
发布于 2019-12-03 03:18:57
遇到了这个问题,不得不深入研究解决方案的源代码。
CdkStepLabel指令将TemplateRef设置为公共。因此,我们可以在CdkStepper子组件中执行以下操作:
<ng-container [ngTemplateOutlet]="selected.stepLabel.template"></ng-container>(然而,您想要访问,正确的步骤由您决定)
希望这对未来的搜索者有所帮助。
https://stackoverflow.com/questions/55790950
复制相似问题