angular - 我如何通过有角度的打字稿访问 MatStep 中的组件
问题描述
我需要在打字稿中访问步进器步骤中的所有组件,我有以下内容:
<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 的东西?
解决方案
根据您的评论,听起来您想根据上一步动态更改步进器内容。我会为此使用基于事件的方法,而不是命令式方法。
一种解决方案可能是将事件从步骤组件发送到父组件。然后让父级渲染适当的更改。
父 HTML
<mat-vertical-stepper #stepper (selectionChange)="ChangeSelection($event)">
<mat-step label="Step 1">
Step 1
<app-comp0 (stateChanged)="step1State.next($event)"> </app-comp0>
</mat-step>
<mat-step label="Step 2">
Step 2
<app-comp1 [step1State]="step1State | async"> </app-comp1>
<app-comp2 [step1State]="step1State | async"> </app-comp1>
</mat-step>
</mat-vertical-stepper>
家长打字稿
step1State = new EventEmitter();
儿童打字稿app-comp0
@Output()
stateChanged = new EventEmitter();
儿童打字稿app-comp1
@Input()
set step1State(newState) {
// Do work here
}
现在Step 2
组件依赖于组件的状态Step 1
。您可以继续此操作,根据每个组件的许多@Input
' 和@Output
' 链接不同的组件。
这也使得推理更容易,因为每个组件只依赖于给定的事件,而不是直接依赖。
推荐阅读
- jsf - 无法访问 primefaces 中的后缀或枚举值
嗨,我目前正在使用 primefaces 开发一个 java 项目 (jsf),并且我正在使用枚举,但我无法使用 primefaces 从视图中访问它的值。我已经通过从 Bean 创建一个 getter 并访问枚举值暂时解决了这个问题,但它应该默认使用 allSuffix = "ALL_ENUM_VALU
- ethereum - 执行 TX 特定 block.timestamp
- python - 如何使用 Python 3.8.5 安装 vtkplotter?
- java - java-处理浮点舍入错误,如何保持弧度合理
- python - 重新缩放拼接图像中的边界框注释
- javascript - 如何创建过滤器以动态呈现获取的项目
- entity-framework - 当 DTO 中缺少某些属性时,如何将 DTO 对象映射到实体?
- azure - 如何在存储资源管理器中使用 SAS URI 将文件夹上传到 Blob 存储
- swift - 隐藏导航栏 SwiftUI for MacOS 11.1
- flutter - 您是否应该在按钮中等待 Navigator 调用