Imagine I would have a component which should receive events, a "player" for instance. The user will likely want to trigger an event to the player, such as "play" or "pause". In my understanding, the @inputs
are basically a value we send to the component (and not an event). What is the good practice to trigger those events to the component ?
Considering a player example: - The player has no UI, it's only a tag able to load a source file. - We need to find a convenient way to drive this player firing events such as "start", "stop", "pause"…
I thought about passing an eventEmitter in parameter such as <player [controls]=controls src="somefile.mp3"/>
where the control
would be the EventEmitter. Then, the component's controller would internally observe this emitter's events and act accordingly (play, stop, pause…).
Any other solution / convention to achieve this ?
More ideas:
- Create custom specific event on the player's dom element then trigger the event
- Find a way to get the component's controller within the code and directly call public functions such as play(), pause()…. but then it might be an antipatern with webworkers.