In my parent component, there are three instances of a child component nested inside.
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 needed to trigger the onSave method in the child component
}
Is it possible to invoke the onSave method of the child component and pass its form object as a parameter?
Thank you.