btford/ngmin

Currently does not inject dependencies names with "resolve"

laurent-le-graverend opened this issue · 5 comments

It does not inject the dependencies on the following case:

We are losing $q and $timeout

  angular.module('myApp', []).config(function($routeProvider) {
    return $routeProvider.when('/', {
      templateUrl: 'views/quiz.html',
      controller: 'QuizCtrl',
      resolve: {
        delay: function($q, $timeout) {
          var delay;
          delay = $q.defer();
          $timeout(delay.resolve, 100);
          return delay.promise;
        }
      }
    }).otherwise({
      redirectTo: '/'
    });
  })

Generate:

  delay: function (a, b) {
    var c;
    return c = a.defer(), b(c.resolve, 100), c.promise;
  }

👍

+1. Having the same problem. Any way to overcome this until ng-min is able to inject dependencies into the 'resolve' function?

Use the inline annotation DI syntax as shown below. This is what ngmin converts inferred DI syntax to.

resolve: {
  delay: ['$q', '$timeout', function($q, $timeout) {
    var delay;
    delay = $q.defer();
    $timeout(delay.resolve, 100);
      return delay.promise;
  }]
}

Duplicate of #35

For now resolved this by putting these lines in package.json

"devDependencies": {
  "ngmin": "git+https://github.com/werk85/ngmin.git",
  "astral-angular-annotate": "git+https://github.com/werk85/astral-angular-annotate.git",
  "astral-angular-annotate-ui-router": "git+https://github.com/werk85/astral-angular-annotate-ui-router.git",
  "grunt-ngmin": "0.0.3",
  ...
}