With multiple parent components needing a common child component that can dynamically and automatically adapt to each case, I am faced with the challenge of generating buttons using a forEach loop with data provided by the parent component (such as name, CSS class, and output name).
My main question is: Is it possible to dynamically create Outputs that directly link to the corresponding parent function?
One potential solution I have considered is to have a single output that sends a string or always integrates with the same parent function, which would then interpret and redirect it to the appropriate function using a switch statement. However, this approach doesn't seem very elegant or efficient to me.
So far, I have attempted to implement this in the child component, but I encountered an error in the editor:
child-component.components.ts
@Input() myButtons: any[];
constructor() {
this.myButtons.forEach(array => {
@Output() array.variableName: EventEmitter<number>;
});
}
Of course, I am sending an array with all the necessary data from the parent:
parent-component.components.html
<app-child-component [myButtons]="buttonsArray"></app-child-component>