0

Hello I created basic angularJS app with angular-translate module. In config except my routing I've got also $translateProvider which is responsible for translations tables and prefered lenguage.

so this code:

$translateProvider.preferredLanguage('en');

is within Angular config() function.

I know that config is executed first, before run(), controllers and others. I also know that in config there must be only providers can't inject for example $rootScope there.

In my project by calling single endpoint using $http I gather information about country which user came into this app. This is happening in run().

I tried to use $rootScope (in this run()):

$rootScope.homeCountry = response.data.country;
$rootScope.homeCountryLower = $rootScope.homeCountry.toLowerCase();
console.log($rootScope.homeCountryLower);

it console out "pl" in my case but I ended up learning that I can not pass $rootScope to config since it is not a Provider.

I need to pass this information to $translateProvider in config function so I would be able to set prefered user lengauge according to user country.

How can I achieve that?

BT101
  • 3,666
  • 10
  • 41
  • 90
  • Possible duplicate of [use $http inside custom provider in app config, angular.js](https://stackoverflow.com/questions/17497006/use-http-inside-custom-provider-in-app-config-angular-js) – cnorthfield Aug 25 '17 at 22:08
  • Why is it duplicate? – BT101 Aug 25 '17 at 22:12
  • Because he thinks your question has been answered over there already. After reading the accepted answer & comments I think so as well - since all I would have written here as an answer has been written there already. – Manuel Manhart Aug 26 '17 at 04:55

0 Answers0