ok. thanks. On Tuesday, March 10, 2015 at 2:47:42 PM UTC-7, Caitlin Potter wrote: > > No, you've got it wrong =) Those styles have nothing to do with local vs > global. They are just different ways of telling the injector what to > inject. The latter of which will not work with minified code, due to name > mangling. > > I can't remember why "locals" came up, I think it was because I was > explaining how to use the $controller() api as an example. Totally > unrelated, though. > > On Tue, Mar 10, 2015 at 5:40 PM, adam morris <[email protected] > <javascript:>> wrote: > >> *So to summarize... * >> >> // The example you provided: >>> angular.controller(“MyController”, >>> >> [“$scope”, “$http”, * //local, not registered w/ injector?* >>> >> function($scope, $http) { *// global, registered w/ injector, and >>> mapped to local?* >>> >> // ... >>> }]); >>> >> >> On Tuesday, March 10, 2015 at 1:53:25 PM UTC-7, Caitlin Potter wrote: >>> >>> So, there are 2 kinds of things that can be injected into a function: >>> >>> - Things which are registered with the injector (eg, things you register >>> via angular.controller(“controllerName”, …)) >>> - Local variables, which are not registered with the injector. >>> >>> You don’t need to worry about the distinction until you’re doing things >>> with the injector, but it really just means that locals allow you to inject >>> things which are not “registered” with the injector. >>> >>> On Mar 10, 2015, at 4:46 PM, adam morris <[email protected]> wrote: >>> >>> Caitlin, I get the gist of the third example. I looked online and found >>> that upon minification, "$scope & $http" are turned to something more >>> generic like "a & b" and those variables would lose their context, breaking >>> the code. So that adding "[“$scope”, “$http”..." either prevents >>> minification (or minification factors in) specifically on those variables. >>> >>> I'm a little fuzzy on global vs local $scope. >>> Is the fact that '$scope' a literal make it a local variable? >>> >>> Thanks. >>> >>> On Tuesday, March 10, 2015 at 11:57:04 AM UTC-7, Caitlin Potter wrote: >>>> >>>> This is a way of interacting with the injector (one of several). The >>>> string literal containing ‘$scope’ tells the injector that the parameter >>>> at >>>> index 0 (first item in the array) should be ‘$scope’ from the injector. >>>> ‘$scope’ isn’t registered globally in the injector, it comes from locals >>>> (so, if you instantiate a controller via the $controller service, you can >>>> supply injector locals via the second parameter, `$controller(‘ctrlName’, >>>> { >>>> $scope: myScope });`. >>>> >>>> There are a few ways to use the injector: >>>> >>>> ``` >>>> // One example: >>>> MyController.$inject = [‘$scope’, ‘$http’]; >>>> function MyController($scope, $http) { >>>> // ... >>>> } >>>> angular.controller(“MyController”, MyController); >>>> >>>> // The example you provided: >>>> angular.controller(“MyController”, [“$scope”, “$http”, >>>> function($scope, $http) { >>>> // ... >>>> }]); >>>> >>>> // The third method is discouraged, because it requires parsing >>>> `function.toString()`, and this >>>> // does not work as expected when code is minified. >>>> angular.module(“MyController”, function($scope, $http) { >>>> // ... >>>> }); >>>> ``` >>>> >>>> These rules apply to everything that the injector deals with, from >>>> directives to services to filters to controllers. >>>> >>>> If that didn’t clear things up, feel free to ask for clarification =) >>>> >>>> On Mar 10, 2015, at 2:44 PM, adam morris <[email protected]> wrote: >>>> >>>> Hi. I'm an angular newbie. I couldn't find an explanation of this part >>>> of a controller anywhere: >>>> >>>> controller('myController', >>>> [*'$scope'*, //mentioned first time - *what does >>>> this do?* >>>> function*($scope)* //mentioned second time - *how does this >>>> ($scope) relate to '$scope' above?* >>>> >>>> -- >>>> 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. >>>> >>>> >>>> >>> -- >>> 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. >>> >>> >>> -- >> 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] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at http://groups.google.com/group/angular. >> For more options, visit https://groups.google.com/d/optout. >> > >
-- 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.
