Double injection in AngularJS via ngInject and ng-annotate

I am using Gulp to generate my main javascript file (app.js) for an AngularJS app. Everything works great except for one little thing that worries me. I am using ng-annotate to automatically parse my jquery angular js syntax and add dependencies. So I went from this (manual injection without using ng annotation):

angular.module('base.controllers')
        .controller('RandomeCtrl',
                ['$scope', '$routeParams', ...,
                    function($scope, $routeParams, ...) { 

      

To this (code to be modified accordingly to ng-annotate):

angular.module('base.controllers')
        .controller('RandomeCtrl', 
                    function($scope, $routeParams, ...) {

      

However, in large projects, if the code is reused or (chokes) cut and paste, either alone or as a set of controllers, I like the warning for my future self, and for other developers, adding annotation /* @ngInject */

. Like this:

angular.module('base.controllers')
        .controller('RandomeCtrl', 
        /*@ngInject*/
                function($scope, $routeParams, ...) {

      

There was an issue with double injection arrays as pointed out here: https://github.com/olov/ng-annotate/issues/28 . However, this does not seem to apply to the same scenario and I was wondering if there is a serious double injection issue that I need to be wary of and I cannot find more information on the consequences.

+3


source to share


1 answer


No need to be afraid! /*@ngInject*/

is a way to tell ng-annotate that you want him to annotate a certain piece of code. If he has already understood this, /*@ngInject*/

he does nothing superfluous and is completely harmless.



+9


source







All Articles