Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Angular config variables according to the current env #903

Closed
pgrodrigues opened this issue Sep 10, 2015 · 1 comment
Closed

Angular config variables according to the current env #903

pgrodrigues opened this issue Sep 10, 2015 · 1 comment

Comments

@pgrodrigues
Copy link
Contributor

I think it could be useful to have some mechanism to inject variables within angularjs logic according to our env. I know that we can pass in some properties from env configs using express and swig and those are indeed dependent in the current env. But today I was reading this part of the Angular docs and I wanted to set both $compileProvider.debugInfoEnabled(false); and ng-strict-di="true" only while in production.

Im not sure if it is possible/correct/safe to set those angular vars the same way we do for the ones with express/swig, so in my app I ended up creating a module like this:

(function () {
'use strict';

angular.module('mean.configs', [])
    .constant('configs', {
        debugInfoEnabled: @@debugInfoEnabled
    });
})();

The @@debugInfoEnabled expression will be replaced using grunt-replace task by matching the pattern @@ and then inject this module in the main mean module.

And then I can access it this way for example:

.config(function ($compileProvider, configs) {
     $compileProvider.debugInfoEnabled(configs.debugInfoEnabled);
});

The downside is that I need to have an extra dummy file with the matching expressions like showed above that will generate the file with the replaced expressions (the one that will be injected).

It is working but there are probably better ways to do it, as this is kind of a question and suggestion at the same time.

Note that this doesn't have anything to do with debugInfoEnabled in particular, it was just an example.

@pgrodrigues
Copy link
Contributor Author

Closing this as I'm now using grunt-ng-constant which achieves what I wanted in a easier way.

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

No branches or pull requests

1 participant