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.

2
  • Why it can't be one and defined output, which will emit certain event object on some action(click smth else)? Commented Sep 7, 2021 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. Commented Sep 7, 2021 at 12:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.