olov / ng-annotate

Add, remove and rebuild AngularJS dependency injection annotations
MIT License
2.03k stars 152 forks source link

ES6 - Dependency injection from translation configuration #247

Closed BkSouX closed 8 years ago

BkSouX commented 8 years ago

Hello,

I'm trying to set up my i18n configuration file but I have an issue with an injection. I'm using ES6 with webpack & babel.

So, I have that code :

import angular from 'angular';
import ngTranslate from 'angular-translate';
import ngSanitize from 'angular-sanitize';

const i18n = angular.module('i18n', [ngTranslate, ngSanitize])
  .config(($translateProvider) => {
    $translateProvider
      .translations('fr', {})
      .useSanitizeValueStrategy('sanitizeParameters')
      .preferredLanguage('fr');
  })
.name;

export default i18n;

And that error in the console :

angular.js?3437:68Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module {"_invokeQueue":[],"_configBlocks":[["$injector","invoke",{}]],"_runBlocks":[],"requires":["pascalprecht.translate","ngSanitize"],"name":"i18n"} due to:
Error: [ng:areq] Argument 'module' is not a function, got Object

ng-annotate works well with controllers but well, I don't know what's going on with that module.

BkSouX commented 8 years ago

Erf it was quick ! I just needed to put 'ngInject'; everywhere

const i18n = angular.module('i18n', [ngTranslate, ngSanitize])
  .config(($translateProvider) => {
 'ngInject';
    $translateProvider
      .translations('fr', {})
      .useSanitizeValueStrategy('sanitizeParameters')
      .preferredLanguage('fr');
  })
.name;