这是我的父组件的样子 .

In HTML

<a href="#" (click)="saveDetails()" #saveDetails>
    <app-tab-product *ngFor="let cat of category"></app-tab-product>//parent component

In Typescript

//In parent component.    
 saveDetails(){
   if(this.saveDetails.nativeElement.hasAttribute("data-action")== "next"){
      //save from child requested on next click.
    }

}

在我正在使用的子组件_1014250中

@ViewChild('saveDetails') saveDetails:ElementRef;//child component (tab-product) 但它显示了未定义的子组件内部 .

this.saveDetails.nativeElement.setAttribute("data-action","next");
  this.saveDetails.nativeElement.click();

子组件内有下一个按钮 . 如果用户单击子组件内的下一个按钮,我想单击父组件的保存按钮,以便保存子组件的数据 . 方法 saveDetails() 在父组件typescript文件中 .