I have a parent component having three instances of child component inside it.
child-product-detail.component.html
<form id="frmProduct" #frmProduct="ngForm" (ngSubmit)="onSave(frmProduct)">
<ng-content select="[buttons-view]"></ng-content>
<input type="text" id="txtProductName" name="txtProductName" [(ngModel)]="product.productName" />
</form>
child-product-detail.component.ts
onSave(form) {
let isValid = this.validate(form);
if (!isValid) return;
}
parent-product.compoment.html
<child-product-detail [product]="products[0]">
<div buttons-view>
<button type="button" class="btn" (click)="saveProduct(0)" >Save</button>
</div>
</child-product-detail>
<child-product-detail [product]="products[1]">
<div buttons-view>
<button type="button" class="btn" (click)="saveProduct(1)" >Save</button>
</div>
</child-product-detail>
<child-product-detail [product]="products[2]">
<div buttons-view>
<button type="button" class="btn" (click)="saveProduct(2)" >Save</button>
</div>
</child-product-detail>
parent-product.component.ts
saveProduct(productId) {
let productToSave = this.products(productIndex);
// Code required to call onSave method of child component
}
Is there anyway I can call onSave method of the child component passing the form object of it?
Thanks.