You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Better error messages when an @Output property is not initialized. #3664
Listing an event in a directive without creating an associated EventEmitter instance results in cryptic error:
TypeError: Cannot read property 'observer' of undefined
at Function.ObservableWrapper.subscribe (angular2.js:19403)
at EventEmitterAccessor.subscribe (angular2.js:26062)
at AppViewManagerUtils._setUpEventEmitters (angular2.js:20932)
at AppViewManagerUtils._hydrateView (angular2.js:20896)
at AppViewManagerUtils.hydrateRootHostView (angular2.js:20814)
at AppViewManager.createRootHostView (angular2.js:23990)
at angular2.js:13594
at Zone.run (zone.js:113)
at Zone.run (angular2.js:12928)
at zoneBoundFn (zone.js:86)
To reproduce:
@Directive({
selector: '[foo]'
})
classFoo {
@Output() foo; // not initialized to = new EventEmitter();
}
Reacted by alexander taylor, robindijkhof, Bobby Mundy, Tree Nguyen, Alberto, Максим Иванов, Dennis Zoma, Mateja Petrovic and Gabor Barat
For me the error stopped when I changed the import statement from import { EventEmitter } from 'events'; to import { EventEmitter } from '@angular/core'. The first option was suggested by angular as default but I think that the second one should be used. Everything works fine now after I changed it.
Example: @output() variableToEmit: EventEmitter = new EventEmitter();
Reacted by Abel Valdez, Trapulo, Alexander Moon, ejpuderer, joancapo, Aniket Thakur, Joaquim Nunes, bsantosh2527, Tiago Teixeira Bonifácio, Natanael Osorio and 7 more
Reacted by Nick Freitas, Natanael Osorio and Niklas Merz
angular-automatic-lock-bot commented on Sep 14, 2019
Activity
fix(ElementInjector): better error message for events with no EventEm…
mhevery commentedon Jul 1, 2016
Is this still an issue? Can you fix it?
11 remaining items
ashish173 commentedon Jan 19, 2017
Yes I also got this cryptic error message. I am going to try to fix this one.
cedvdb commentedon Apr 16, 2017
When subscribing to the non initialized EventEmitter in the template eg:
The error message is also not very precise as of where the error is coming from.
aldo-roman commentedon Jan 16, 2018
Hi @mhevery @vicb
I submitted a PR for this issue some time ago. I just fixed a conflict, lint errors and tests. See #19116
Please let me know if there is something I can do. Cheers!
splincode commentedon Jul 26, 2018
@pkozlowski-opensource Is the issue relevant?
Will this pull request be accepted?
#19116
fix(core): throw error message when @output not initialized
luisfelix199276 commentedon Nov 20, 2018
For me the error stopped when I changed the import statement from import { EventEmitter } from 'events'; to import { EventEmitter } from '@angular/core'. The first option was suggested by angular as default but I think that the second one should be used. Everything works fine now after I changed it.
Example:
@output() variableToEmit: EventEmitter = new EventEmitter();
showsString(text: any) {
this.variableToEmit.emit(text);
}
Hope that helps .
angular-automatic-lock-bot commentedon Sep 14, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.