0

Sorry if the title is wrong cause i couldn't figure out the best title for it. You can change it if you want to

Constant File

/* global lodash:false */
(function () {
    'use strict';

    angular
        .module('blocks.router')
        .constant('lodash', _);  
})(); 

routerHelper.js File

 /* @ngInject */

function routeHelper($location, $rootScope, $state, _, logger, routeHelperConfig)

 routeHelper.$inject = ['$location', '$rootScope', '$state', '_', 'logger', 'routeHelperConfig'];

Problem

Manually injecting the dependencies works fine.

routeHelper.$inject = ['$location', '$rootScope', '$state', 'lodash', 'logger', 'routeHelperConfig'];

But When i run ng-annotate cmdline (ng-annotate --single_quotes --add routeHelper.js -o routeHelper.js) it creates following

routeHelper.$inject = ['$location', '$rootScope', '$state', '_', 'logger', 'routeHelperConfig'];

You can see the difference with ng-annoate spitting out '_' instead of 'lodash'.

Question

how can i control ng-annoate to not replace the 'lodash' with '_'

Chief
  • 914
  • 1
  • 9
  • 26

1 Answers1

1

ng-annotate tries to be as smart as possible but it cannot read your mind! :-) If you have a different name for your parameter than the injected service/constant/whatever, then you simply have to specify the $inject array for the program to run. If you don't, the program won't run (minified or not).

So ff you must do this, then just add the $inject array manually. ng-annotate will leave it intact as long as you run it with --add and not --add --remove.

olov
  • 391
  • 3
  • 4
  • Thanks olov .. Manualy injecting array works fine. The idea is to make it automatic and still avoid the replacement with 'lodash' with '_' – Chief Sep 28 '14 at 23:55
  • 1
    Either: 1. `angular.module(foo).constant("lodash", _) then function routeHelper(lodash) {}` or 2. `angular.module(foo).constant("_", _) then function routeHelper(_) {}` or 3. provide explicit annotation arrays. – olov Oct 09 '14 at 12:29