-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for 'controllerAs' syntax in event callbacks #235
Conversation
@niclassahlin: thanks for the PR. However, I'd already implemented support for Did you find any issue/bug in existing implementation? |
@codef0rmer The syntax worked so it referred to the correct function after the parsing. However, the function is always executed in the context of the scope, which means if you use a prototype based controller then You can see an example of this, where I use a Typescript class to generate the controller function (you'll see the exception in the console). This is basically how we have built all of our Angular components. We try to use the controller object and avoiding the scope as much as possible to get a smoother transition to Angular 2. Sorry if the title is a bit misleading. |
@codef0rmer Do you have any input? We are quite dependent on this fix and I don't want to diverge from the standard library too much, so any feedback would be highly appreciated. |
Hey @niclassahlin, I'm slightly loaded, I'll take some time out this weekend to review your PR. |
@niclassahlin I believe only following change is required. If you log Can you please confirm if following fix works for you? |
@codef0rmer I added your fix instead of mine and it seems to work. I think the difference between our fixes are how we choose the context when there is a method on both the scope and the constructor, but I think that it is uncommon to mix the two styles so I don't think it is that important. So yes, your fix seems to fix it :) Thanks! |
@niclassahlin: Thanks. Regarding two styles, you can define a method on |
@codef0rmer theoretically it could occur, but I don't see any practical reason why it would. I think that either |
@niclassahlin Alright my friend, I'll merge my commit 👍 |
Sweet 👍 |
Added support for using
controllerAs
syntax when defining event callbacks such asonDrop
.Instead of always setting the scope as context to the callback, it now sets the constructor to the context is the constructor exists on the scope. Uses of
this
in the callback should therefore refer to the controller.