【发布时间】:2020-03-31 10:02:04
【问题描述】:
我需要在 typescript 中访问 stepper 步骤中的所有组件,我有以下内容:
<mat-vertical-stepper #stepper (selectionChange)="ChangeSelection($event)">
<mat-step label="Step 1">
Step 1
</mat-step>
<mat-step label="Step 2">
Step 2
<app-comp1> </app-comp1>
<app-comp2> </app-comp1>
</mat-step>
</mat-vertical-stepper>
知道comp1和comp2实现IComp(自定义接口)
export interface IComp {
MethodeFromInterface?: { (data?: any): void }; //this is optional
}
export class Comp1 implements IComp {
MethodeFromInterface(data: any) {
//do something here
}
}
export class Comp2 implements IComp {
MethodeFromInterface(data: any) {
//do something here
}
}
主要成分有
ChangeSelection(event) {
var m = (<IComp>event.selectedStep);
if (m.MethodeFromInterface.InnerComponents[0]) // InnerComponents is an example
m.MethodeFromInterface("TEST");
}
那么 MatStep 里面有没有类似 innerComponents 的东西?
【问题讨论】:
-
为什么您需要访问步骤中的所有组件?如果是用于验证,您可以在每个步骤中使用
stepControl属性 -
下一步应该加载的内容取决于上一步的输入我将使用传递参数的方法加载内容
标签: angular typescript angular-material-stepper