In AngularJS 2, directives can announce / trigger output events using the EventEmitter class (ng.core.EventEmitter). Each output must get its own instance of the EventEmitter class, which means that you must instantiate the EventEmitter when you are implementing your output event stream. If you forget to "new" the EventEmitter, such as typing:
this.myEvent = ng.core.EventEmitter();
... you will get the following error:
EXCEPTION: TypeError: Cannot read property 'subscribe' of undefined.
Notice that I forgot to "new" the EventEmitter into existence. Invoking it in this way downgrades the EventEmitter() constructor into a simple "function call". The fix is easy - just add "new":
this.myEvent = new ng.core.EventEmitter();
I've tripped over this like at least 4 or 5 times already this week; so, I figured I'd just make a record of it incase anyone also runs into the error and tries to Google for the error message.
Looking For A New Job?
- Software Development Engineer - REQ20003869 at Express Scripts
- Mobile Application Developer at Xorbia Tickets
- 7 Year + Lead ColdFusion Developer at Atprime Media Services
- Full Time ColdFusion Developer Needed at InterCoastal Net Designs
- Developer-focused job platform at Honeypot
Yep, stumbled across the same...
Thanks for posting, I'm sure it will help quite a few people
Thanks for the feedback. I have 2 other befuddling errors that I think I'll write up for reference.
Yup, same boat here. Thank you for sharing this!
Just hit this today, having forgotten to new the EventEmitter. Thanks, Ben!
Woot - glad this helped :D
Thanks for this - Saw this error when i set up an Output without wiring it up and had no idea why the error was appearing or what it meant.
What a waste of an hour, running around trying to figure out where I was trying to call 'subscribe'. Course, this makes complete sense!! Thanks!