Angular中父组件调用子组件的方法
作者:互联网
// 父组件TS文件:
// 1. 引入子组件 和 ViewChild
import { CompanyAddEditComponent } from './company-add-edit/company-add-edit.component';
import { ViewChild } from '@angular/core';
// 2. 注解子组件
export class WexternalPartiesComponent implements OnInit {
@ViewChild('CompanyAddEditComponent', { static: true })
CompanyAddEditComponent: CompanyAddEditComponent;
// 3. 调用
do() {
this.CompanyAddEditComponent.子组件方法();
}
}
标签:company,add,CompanyAddEditComponent,ViewChild,中父,组件,import,Angular 来源: https://www.cnblogs.com/suihung/p/16459104.html