0
First of all, excuse my Portuguese, I don’t write it well and I’m using a translator, but I can read it well enough.
I have several parent components and created a common child component for all of them that must adapt dynamically and automatically to each case, among them several buttons that will be generated with a forehead using the data sent by the parent (name, CSS class and Output name).
The question is: I can create Output in a dynamic way that points directly to the function of the corresponding parent?
A quick solution that occurs to me is to use only an output that sends a string or integrates always to the same function of the father and that this interprets it and the drift to the corresponding function with a switch but it seems to me a solution not very "elegant" and efficient.
For now I tried to do this in the child component, but the editor himself gives me a mistake:
componenteHijo.components.ts
@Input() misBotones: any[];
constructor() {
this.misBotones.forEach(array => {
@Output() array.nombreVariable: EventEmitter<number>;
});
}
Of course I’m sending from the main component a matrix with all the necessary data:
componentePadre.components.html
<app-componente-hijo [misBotones]="botonesArray"></app-componente-hijo>
better would be one only you change the die according to the button
– Eduardo Vargas
Yes, but it can be a button or more than one.
– ivanao