代码如下:

@Component({
    selector: 'my-app',
    template: `
        <step-bar #stepBar></step-bar>
    `
})
export class AppComponent{
    //利用模板变量stepBar获取子组件的引用
    @ViewChild('stepBar') stepBar: StepBarComponent;
    //执行子组件的init方法(需要在AfterViewInit钩子后执行)
    ngAfterViewInit() {
         this.stepBar.init();
    }
}

相关文章:

  • 2021-09-20
  • 2022-12-23
  • 2022-03-04
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-02
  • 2022-02-23
  • 2022-02-12
  • 2022-12-23
  • 2021-06-06
相关资源
相似解决方案