0

For the sake of simplicity, Let's say we have a MyComponent with an @Input() eventName = 'signal'.

I would like to use the value signal as the name of a dynamically created EventEmitter. Which I can use as a regular @Output as so:

<my-component [eventName]="'signal'" (signal)="onSignal()"></my-component>

My actual use case needs an array of "event" objects which would contain some other info for the template apart from the unique name to be used as the @Output name.

Alex Pappas
  • 2,377
  • 3
  • 24
  • 48
  • Why it can't be one and defined output, which will emit certain event object on some action(click smth else)? – vitaliy kotov Sep 07 '21 at 11:32
  • Imagine you have a component where you want to allow the user to define a list of actions which you would render as described per object (like a configuration). you can simply loop through the list of objects, use its properties on the template to decide how each buttons are rendered and have all of them `emit` one `@Output` named `actionCLick`, for example, which you can use to return some info on which action was clicked. The sole purpose of this requirement in the question is to eliminate the need to return the action name on `emit` and check for it on the parent component. – Alex Pappas Sep 07 '21 at 12:03

0 Answers0