If you are minifying however, you are probably running a build task, so you
could use ng-annotate project to automatically annotate your code. This
means that you can write in the style of #3 and not worry about annotating
the injects. I find this much simpler. In the case of being verbose, use
the hint:


angular.module(“MyController”, /* @ngInject */ function($scope, $http) {
  // ...
});
```

On 10 March 2015 at 11:56, Caitlin Potter <[email protected]> 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.
>



-- 
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.

Reply via email to