我有一个步进器组件。在stepper-component.html中,我有四个组件作为mat-step,如下所示-
<div class="container-fluid">
<mat-horizontal-stepper linear #stepper>
<mat-step label="Step1">
<component-1></component-1>
</mat-step>
<mat-step label="Step2">
<component-2></component-2>
</mat-step>
<mat-step label="Step3">
<component-3></component-3>
</mat-step>
<mat-step label="Step4">
<component-4></component-4>
</mat-step>
</mat-horizontal-stepper>
</div>我想通过点击不同组件中的一个按钮来访问component2,比如componentX,并在component2中执行一些函数。我该怎么做呢?
发布于 2020-09-18 13:52:21
您可以使用@Input() / @Output(),也可以直接在componentX中导入component2并调用该方法。例如,在您的componentX中:
constructor(private component2: Component2) {}
clickMethod() {
this.component2.method();
}https://stackoverflow.com/questions/63949997
复制相似问题