1

我有一个步进组件。在 stepper-component.html 中,我有四个组件作为 mat-steps,如下所示 -

<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>

我想通过单击不同组件中的按钮来访问组件2,比如组件 X,并在组件 2 中执行一些功能。我怎样才能做到这一点?

4

1 回答 1

0

您可以玩@Input()/@Output()或者您可以只在您的 componentX 中导入 component2 并调用该方法。例如在您的 componentX 中:

constructor(private component2: Component2) {}

clickMethod() {
    this.component2.method();
}
于 2020-09-18T05:52:20.973 回答