0👍
✅
You are using the event hub pattern correctly, so your code works.
Some points may be preventing you from seeing the listener ($on
) working:
- The listener is declared in
abc.js
. Simply declaring it does not guarantee that it is executed. Make sureabc.js
is imported somewhere so the code executes and the listener is properly registered. - The
$emit
event code is triggered by a method that is on av-on:change
. For<input>
s, thechange
event happens when theinput
s lose focus, not on typing. The event that happens char by char isinput
(or thekey*
events, naturally). So type some text and focus out theinput
to see the event triggered. - If your question code is just a demo and the code that triggers the event is another
.js
file, make sure it executes after theabc.js
does.
The demo above handles these cases.
Source:stackexchange.com