Instance bound methods do not work as hooks #16478
Labels
area: core
Issues related to the framework runtime
core: lifecycle hooks
feature
Issue that requests a new feature
Milestone
I'm submitting a ... (check one with "x")
Instance bound methods do not work as hooks. Here is a little code sample:
Current behavior
Hook is not executed, "Hello Angular" is displayed.
Expected behavior
Hook should be executed, and we would see "Hello World" instead. Or (if it is by design) - some message would be much appreciated in DEV mode. Smth like, "You are trying to use instance bound method for hooks. It will not work."
In the documentation i found only this note:
Which is explaining it in some manner, but intention is not clear still.
Minimal reproduction of the problem with instructions
StackOverflow discussion:
http://stackoverflow.com/questions/43677584/angular2-instance-bound-methods-does-not-work-as-hooks
Plunkr: https://plnkr.co/edit/aZ1CYkDn06KUENmDW3a3?p=preview
What is the motivation / use case for changing the behavior?
It is kinda not transparent why Angular is behaving like that. I assume that it is by design for performance reasons. But it would be nice to mention that explicitly and provide a message for DEV mode to prevent others from spending time on such thing.
BTW, React is behaving in a predictable manner:
Hook is called and it displays "Hello! React" as you would expect.
JSBin for exploration: https://jsbin.com/yavokur/1/edit?js,output
Please tell us about your environment:
OSX El Capitan 10.11.6
VSCode
Express-based node.js server
Angular version: 2.0.X
angular: 4.1.0
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
ALL
Language: [all | TypeScript X.X | ES6/7 | ES5]
TypeScript 2.3+
Node (for AoT issues):
node --version
=node: 4.7.3
The text was updated successfully, but these errors were encountered: