I want to define some application settings , but I want to provide different values depending on whether I'm running in 'debug' mode (eg grunt serve
), or whether the final compiled app is running (eg the output of grunt
). That is, something like:
angular.module('myApp').factory('AppSettings', function() {
if (DebugMode()) { // ??
return { apiPort: 12345 };
} else {
return { apiPort: 8008 };
}
});
How can I accomplish this?
The way I handle it in my apps:
grunt-template
as part of your build - for example: app.constant('myAppConfig', {bananaHammocks: <%= banana.hammocks %>});
grunt-stage
to switch grunt config values depending on environment: create your different config/secret/(env).json
files, update your template ( app.constant('myAppConfig', {bananaHammocks: <%= stg.banana.hammocks %>});
), and then grunt stage:local:build
or grunt stage:prod:build
I find this the good balance between complexity and features (separation between environments, runtime code not concerned with building options,...)
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.