Hi Alec,
It depends mostly on personal preference. Both approaches have their own
pre en cons.
the controllerAs/this approach is more locally contained. This helps
portability, but it makes
it more difficult to use in a larger hierarchy.
As a disclaimer, this is my personal view on this!
And now for my own fun, I will confuse you a bit more :-P If you don’t want
to, stop reading here!
You have been warned!
The this/controllerAs system works on top of the scope system. Let me give
you a small code sample:
<div ng-controller='firstController as first'>
<div ng-controller='secondController as second'>
<h1> I'm a higly complex app!!! :-)</h1>
<div>ant the message is: {{message}}</div>
<button ng-click='second.proxyFirst()'>Reveal message</button>
</div>
</div>
app.controller('firstController', function() {
//lo Ma, no scope!
this.msg = 'Hello world'
})
app.controller('secondController', ['$scope',
function($scope) {
this.proxyFirst = function() {
$scope.message = $scope.first.msg;
};
}
]);
While this will work well (see this plunk
<http://plnkr.co/edit/S9mxgO0tEMa0bfTz4Dzq?p=preview>), it clearly
demonstrates that it is easy to make a mess!
So don’t try this at home!
Regards
Sander
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.