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
When I'm using the Component events config it hooks up the handler with an incorrect this context. I would expect this to reference the App class instance, but it actually references the Home class instance.
@Component({selector: 'home'})
@View({template: "<p>Home</p>",// Here I'm setting up a 'foo' eventevents: {foo: "foo"}})classHomeComponent{constructor(){// See here that I'm adding a property to Homethis.wtf="wat?";}}
@AsModule('AppModule',[HomeComponent])
@Component({selector: "app"})
@View({// Here I'm using the on-foo event and passing a reference to the App's doFoo methodinline: `<home on-foo="doFoo"></home>`})classAppComponent{doFoo(){// Here is where things fell apart for me and 'this' was not what I expectconsole.log(this)// HomeComponent {wtf: "wat?"}, expected an instance of AppComponent}}bootstrap(AppComponent)
The text was updated successfully, but these errors were encountered:
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.
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.The text was updated successfully, but these errors were encountered: