the 'controller as' feature simply adds your controller 'as' a variable on the $scope, so that you can reference it. This means that you can set values to the controller via 'this.myVar = xxx' and then reference them as myCtrl.myVar in the template. (where you have set ng-controller="SomethingCtrl as myCtrl")
So, anything that you assign to the controller is exposed to the template. You are assigning the services as properties of the controller.. so this makes perfect sense - no? On 28 April 2014 12:13, divisivecottonwood <[email protected]> wrote: > I've been experimenting with different code design patterns in my > controllers and services > > My starting point was Josh Carroll's 5 Guidelines For Avoiding Scope Soup > in Angular [ > http://www.technofattie.com/2014/03/21/five-guidelines-for-avoiding-scope-soup-in-angular.html > ] > > As an example of a controller > > var app = angular.module('myApp'); > > var Ctrl = function($rootScope, $log, $timeout) { > this.$rootScope = $rootScope; > this.$log = $log; > this.$timeout = $timeout; > }; > > Ctrl.$inject = ['$rootScope', '$log', '$timeout'']; > > Now, if I was to use a code like this in the controller and inject a > config object of constants or my own service, like this: > > var app = angular.module('myApp'); > > var Ctrl = function($rootScope, $log, $timeout, aService, CONFIG) { > this.$rootScope = $rootScope; > this.$log = $log; > this.$timeout = $timeout; > this.aService = aService; > this.CONFIG = CONFIG; > }; > > Ctrl.$inject = ['$rootScope', '$log', '$timeout', 'aService', 'CONFIG']; > > When I use AngularJS Batarang to examine the models I see that aService or > CONFIG is being added to the scope model. > > It's like, hold on, I want to use the values or methods of the constants > or service, not add them to the model as well. > > I'm clearly getting confused here. Can somebody provide me with some > guidance about how to use a class-based approach without creating > unnecessary models in the process > > -- > 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. > -- Tony Polinelli -- 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.
