Below is my code
parent component.ts
data = [{
"name":"This is my name",
"editButton": {
"name":"Edit",
"click":"editMethod()",
},
"addButton": {
"Name":"Add",
"click":"addMethod()"
}
}]
editMethod(rowVal){
console.log("calling edit");
}
addMethod(rowVal){
console.log("calling add");
}
parent.html
<button-app [childdata]="data" (opmethod)="iDotknowtoCallMethod()"></button-app>
childComponent.ts
@Input()
childdata;
@Output()
opmethod = new EventEmitter<string>();
child component.html
<div *ngFor="let ech in childdata">
<label>{{ech.name}}</label>
<button *ngIf="ech.editButton" (click)="ech.editButton.click" >{{ech.editButton.name}}</button>
<button *ngIf="ech.addButton" (click)="ech.addButton.click">{{ech.addButton.name}}</button>
</div>
We can call the parent method using emit
, that is not my question.
I am trying to call the parent method, which names are provided in the data
object. But I am not having any Idea how to call this method.