-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Update all documentation examples to the 'controller as' syntax introduced in 1.5 #5076
Comments
The question is though, why? I haven't used this ever, and from trivial examples it doesn't seem to add anything that can't be done without it. There's even an example in the docs where this leads to non-working code: |
@Narretz - internally at Google the "controller as" is now the recommended approach. If there is a bug with using it then we should address that. I agree with you though that it is not my preferred syntax and have never used it in any app that I wrote. |
@petebacondarwin Do you know why Google switched to using 'controller as' internally? |
Two reasons, I believe:
|
@Narretz I don't see how that is non-working code. As far as I can tell, $scope is never injected into the controllers, so @petebacondarwin This may not be the right place to ask, but it isn't clear to me how it is easier to provide methods than it would be just to attach everything to the scope, as is the norm for Angular controllers. Am I right in thinking that if 'controller as' is used consistently, this isn't in fact an edge case, but a restructuring of how controllers are used in general? Can you give an example where a child controller might hide the properties of a parent controller? More to the point; is there a way to submit a draft PR? I can start working on this, but I'm not entirely sure why one would use 'controller as' at the moment. |
@petebacondarwin Thank you, I'll see if I can fashion a PR based on this. |
@RichardLitt I see now that this is indeed because $scope is not injected in the example that uses controllerAs syntax. The reference to $route.current.scope.name should simply be removed. In my opinion, changing all examples to controllerAs syntax is a bigger issue than it seems. controllerAs is a very different approach (not necessarily more complex). There are already many many tutorials etc. on angular out there, and most use $scope injected into controllers. What happens if all examples in the official docs have changed? There'll be a huge mismatch between what people have seen and what is used on the official docs. Don't forget, we'd probably have to change the whole tutorial, too ... And wasn't there a big discussion about publishing the controller on the scope? Because the whole controller is now accessible. I also remember a reverted commit about private scope fields. Was this ever cleared up? I say let's start with this in angular 2.0 (if it si going to be the recommended way there), and maybe add more info about this in the current docs. |
+1 IMO |
$route.name.scope.current returns undefined in the docs example, as scope is never injected into the relevant controller. Scope doesn't need to be there, so it's best to just remove it. Suggested in angular#5076:
$route.name.scope.current returns undefined in the docs example, as scope is never injected into the relevant controller. Scope doesn't need to be there, so it's best to just remove it. Suggested in angular#5076
$route.name.scope.current returns undefined in the docs example, as scope is never injected into the relevant controller. Scope doesn't need to be there, so it's best to just remove it. Suggested in angular#5076.
$route.name.scope.current returns undefined in the docs example, as scope is never injected into the relevant controller. Scope doesn't need to be there, so it's best to just remove it. Suggested in angular#5076.
Using `controller as` in the template is not described well in the docs, as both `scope` injection and `this` are presented equally without too much discussion of the advantages of using either. I added a bit more discussion based on google's internal style guidelines. Should close angular#5076 until Angular 2.0 comes out and we refactor everything.
I added some more documentation based on this discussion in #7591. I agree we shouldn't change all of the docs until Angular 2.0. |
Using `controller as` in the template is not described well in the docs, as both `scope` injection and `this` are presented equally without too much discussion of the advantages of using either. I added a bit more discussion based on google's internal style guidelines. Should close angular#5076 until Angular 2.0 comes out and we refactor everything.
Using `controller as` in the template is not described well in the docs, as both `scope` injection and `this` are presented equally without too much discussion of the advantages of using either. I added a bit more discussion based on google's internal style guidelines. Should close angular#5076 until Angular 2.0 comes out and we refactor everything.
Using `controller as` in the template is not described well in the docs, as both `scope` injection and `this` are presented equally without too much discussion of the advantages of using either. I added a bit more discussion based on google's internal style guidelines. Closes #7591 Closes #5076 (until Angular 2.0 comes out and we refactor everything)
If you're working on a doc task related to this issue, please note here to prevent duplication of effort.
See http://docs.angularjs.org/api/ng.directive:ngController for an example of 'controller as' syntax
The text was updated successfully, but these errors were encountered: