title: How to preload a config file in angular2
body: <p>I am helping to develop an angular2 web app using webpack, and our current plan is to open up some sort of file for configuring the functionality of our application (.json probably). This would mostly be to give the people implementing our app an easy-to-locate file to specify things like: where their API is located, if they want to add custom stylesheets, etc.</p>
  
  <p>The service I'm using to load my config file looks like this:</p>
  
  <pre><code>//config.ts
  @Injectable()
  export class Config {
      private static _config: Object;
      private static _promise: Promise&lt;any&gt;;
  
      constructor(private http: Http) {
          Config._promise = this.load();
      }
  
      load() {
          return new Promise((resolve, reject) =&gt; {
              this.http.get(`./config/development.json`)
                  .map((response: Response) =&gt; response.json())
                  .catch((error: any) =&gt; {
                      console.error(error);
                      return Observable.throw(error.json().error || 'Server error');
                  })
                  .subscribe((data) =&gt; {
                      Config._config = data;
                      resolve(true);
                  });
          });
      }
  
      get(key: any) {
          return  Config._config[key];
      }
  }
  </code></pre>
  
  <p>And I am using it in another service class:</p>
  
  <pre><code>//api.service.ts
  @Injectable()
  export class ApiService {
      private URI: string;
  
      constructor(private http: Http, private _config: Config) {
          this.URI = this._config.get('apiUrl');
      }
  
      getCustomQueries(): Observable&lt;any&gt; {
          return this.http
              .get(`${this.URI}/CustomQuery`)
              .map((response: Response) =&gt; {
                  let data = response.json();
                  return { QueryID: data.id, QueryName: data.name };
              })
              .catch(this.handleError);
      }
  }
  </code></pre>
  
  <p>I'm wondering if there is a way to load config.ts either:</p>
  
  <ol>
  <li>Before bootstrapping the application's root component</li>
  <li>Before ApiService gets instantiated</li>
  <li>Before a service method from ApiService gets called</li>
  </ol>
  
  <p>OR</p>
  
  <ol start="4">
  <li>Some entirely other way of adding configurability to an angular2 application.</li>
  </ol>