Angular利用@ViewChild在父组件执行子组件的方法

代码如下:

@Component({
    selector: 'my-app',
    template: `
        
    `
})
export class AppComponent{
    //利用模板变量stepBar获取子组件的引用
    @ViewChild('stepBar') stepBar: StepBarComponent;
    //执行子组件的init方法
    this.stepBar.init();
}

你可能感兴趣的:(Angular利用@ViewChild在父组件执行子组件的方法)