Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use envService in config section #10

Closed
fabwu opened this issue Mar 30, 2016 · 2 comments
Closed

Use envService in config section #10

fabwu opened this issue Mar 30, 2016 · 2 comments

Comments

@fabwu
Copy link

fabwu commented Mar 30, 2016

Thanks Juan you write a very useful module and I looking forward to use this on my next angular project.

But I'd like to use the envService in the Angular config section like so:

angular.module('myModule', []).config(function(envService) { 
    console.log(envService.get());
}).

I don't think that is possible because envService is after the config phase available. Do you have a tipp to solve this issue?

@juanpablob
Copy link
Owner

Hello @wuethrich44, first of all, sorry for the delay. I'm afraid it's not possible to use envService within config since the module it self is being used for initialization into de Angular app. I'll try to find a workaround for this issue and I'll let you know.

Cheers!

@mwakerman
Copy link

Hi @wuethrich44, I was having a similar problem but managed to get the information from the envServiceProvider which has the same API as the envService. See this snippet:

app.config(function ($stateProvider, $urlRouterProvider, envServiceProvider) {

  envServiceProvider.config({
    domains: {
      development: ['localhost']
    },
    vars: {
      development: {
        API_URL: 'http://localhost:5000',
      }
    }
  });
  envServiceProvider.check();

  $stateProvider
    .state('home', {
      url: '/',
      templateUrl: 'app/home/home.tpl.html'
    })
    .state('account', {
      url: '/account',
      templateUrl: 'app/account/account.tpl.html',
      controller: 'AccountCtrl',
      data: {requiredLogin: true}
    })
    .state('login', {
      url: '/login',
      templateUrl: 'app/account/login.tpl.html',
      controller: 'AccountCtrl',
      data: {requiredLogout: true}
    });

  $urlRouterProvider.otherwise('/');

  envServiceProvider.get() // returns 'development' when running locally.
  envServiceProvider.read('API_URL') // return  'http://localhost:5000'

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants