Angular 2 – How to use config files

When working in ZF2 we use configuration files that may vary from developer to developer and between production and staging environments. Its pretty convenient and as such I want to replicate this for Angular 2.

How it works in ZF2: We have a config folder with configs named: settings.local.php and settings.global.php. We then use a gitignore file to ignore anything with local in it.

I would like to do something similar with Angular 2 and am not 100% sure of the best method to go about this.

For Angular 2 I was thinking of having a config folder and then using a service to grab the configuration files…

Is there a convention for something like this in Angular 2?

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

I also come from a ZF2 background and wanted this sort of functionality. I can’t promise that this is the ‘convention’ for achieving this however it works perfectly for me and my situation. In short I use a combination of JSON config files and grunt-ng-constant (requires Grunt obvs..) My ngconstant config in my Gruntfile.js looks like this: ngconstant: { options: { constants: { config: grunt.file.readJSON('config/config.global.json') }, name: 'constants', dest: 'public/js/src/config.js', wrap: '/* global angular */nn(function ()n{nt'use strict';ntnt{%= __ngModule %}ntn})();n' }, dev: { constants: { config: grunt.file.readJSON('config/config.dev.json') } }, live: { constants: { config: grunt.file.readJSON('config/config.live.json') } } } The location of… Read more »