简体   繁体   中英

Inject variable inside Config

I have this config

angular.module('moduleApp.config')
.config(['$translateProvider', '$languageSupportProvider',
         function($translateProvider, $languageSupportProvider) {
   // I need to access myService.getLocale();
}]);

My service

angular.module("moduleApp.services")
.service("moduleApp.MyService", MyService);

MyService.$inject = [];

function MyService() {

    this.getLocale = function() {
        // etc
       return "en";
    };
}

If I try to add the service in the config I get an error. How can I get the service data inside the config?

angular.module("moduleApp")
.service("MyService", MyService);

function MyService() {

    this.getLocale = function() {
        // etc
       return "en";
    };
}
.config(['$translateProvider', '$languageSupportProvider', 'MyService'
         function($translateProvider, $languageSupportProvider, MyService) {
   var locale = MyService.getLocale();
}]);```

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM