--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
Exposing your entire controller to your views is bad practice IMO. $scope is a great way to mimic a presentation model/view model/whatever you want to call it while keeping the controller itself focused on logic. Especially considering the fact that exposing the whole controller was already possible via $scope.ctrl = this, I really don't get why this was added. Its existence will be seen by many devs as a recommendation for use. Angular is great, but it's demos and docs already have a reputation for encouraging/showing bad practices not appropriate for real world development. This feature will only increase that perception.
What difference?
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
What difference?
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
There doesn't seem to be much difference. As ben was saying it's just that the new syntax is suggesting that its a good idea (maybe it is). It was possible before, but just because you 'can' do something doesn't mean that you should. I'd like to hear a comment on the thoughts behind this - is it recommended practice?
Do you see how $scope could have been replaced with "this" without adding the "Controller as" syntax?
It may seem like a small difference but it sounds like the complaint is about how "Controller as" was implemented, not that "Controller as" was a bad idea in itself.
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/84selECbp1I/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
Like a controller other than the one you're "in"? That's an even worse idea...
--
--
- Your entire controller is not exposed (if I understand correctly). Don't use the 'this' in syntax 'this.mVariable' to keep methods & data encapsulated.
Visit this group at http://groups.google.com/group/angular.
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.
Or a scope.watchController method...
(I'm not confortable using CTRL as syntax until something solve this)
I guess my concern here is I would be able to do controller.$q.anyExposedProp from the view which I would like to prevent.
Is there any way to achieve this in Typescript?
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
Having controller be the scope would bring a lot of problems into the picture - you would only be able to use inheritance rather then composition to construct you scope objects, which would essentially cripple a dynamically typed language like JS.
Right now Angular mostly relies on mixins type of composition (each controller adds methods and properties directly to the scope object). "Controller as" gives you a shortcut to more classical composition (controller encapsulates all the needed functionality and becomes a well isolated part of the scope object). To understand why this is better - consider this two situations:1.) You have an element like <div ng-controller="Ctrl1" ng-directive1 ng-directive2 >...</div>, where both directives have controllers of their own. No single controller can become the whole scope. You can either have them all mix into the same scope, or, as i prefer, attach themselves to it. The second way is just much cleaner and less prone to naming collisions.
2.) Think broader about controllers then just Angular controllers. Think of the scope as just another dependency (an optional one at that). As i said earlier, "This allows you to reuse controllers from the world of Angular in, say, NodeJS and bring non-angular controllers into your code with few-to-non modifications needed. You are creating it in a way that is more universal across all of JS, not specific to one framework." With that, you usually also get a much cleaner Separation of Concerns.As for the barely referenced part - there isn't much to reference beyond" '<div ng-controller="CountController as CountCtrl" >...</div>' roughly the following happens '$scope.CountCtrl = new CountController(...dependencies)' "
app.controller('MyCtrl', function($scope) { $scope.var1 = "this is var1"; $scope.var2 = "this is var2"; this.scope = $scope;});.
<div ng-controller="MyCtrl as my">