Open timkindberg opened 9 years ago
Yes. this is a somewhat known bug (I did a quick and dirty implementation of the events -- should have noted this problem since I knew about it when it was implemented). Unfortunately it's not exactly easy to fix given Angular 1.x's way of working. I intend to give it a fix, but it may take a bit.
The work around for now is to bind the function before you pass it. i.e. for the class you listed:
class AppComponent {
constructor() {
this.doFoo.bind(this);
}
doFoo() {
console.log(this) // should still be AppComponent
}
}
Thanks for responding! For now we are ditching the formal usage of classes and just writing everything in the class constructor. That allows me to use the let self = this;
reference.
When I'm using the Component events config it hooks up the handler with an incorrect
this
context. I would expectthis
to reference the App class instance, but it actually references the Home class instance.