title: angular2 setup mock environment using JSON file
body: <p>I am trying to set up a mock environments as follows inspired by <a href="https://stackoverflow.com/questions/41423716/environment-specific-service-endpoint-in-angular2-with-angular-cli">this</a>.</p>
  
  <p><strong>environment.mock.ts</strong></p>
  
  <pre><code>export const environment = {
    production: false,
    PRODUCT_LIST : 'http://localhost:4200/app/mock-json/products.json',
    SAVE_CART : 'http://localhost:4200/app/mock-json/cart.json'
  };
  </code></pre>
  
  <p><strong>environment.ts</strong></p>
  
  <pre><code>export const environment = {
    production: false,
    PRODUCT_LIST : 'http://x.x.x.x:9000/service/products',
    SAVE_CART : 'http://x.x.x.x:9000/service/cart'
  };
  </code></pre>
  
  <p><strong>Service Method</strong></p>
  
  <pre><code>getCartData (request: string):Promise&lt;Cart[]&gt;{
      return this.http.post(environment.SAVE_CART, request)
                  .toPromise()
                  .then(response =&gt; {
                          .....
                  })
                  .catch(this.handleError);
    }
  </code></pre>
  
  <p>While I am running with <code>ng serve</code> then everything is running fine with original service endpoint.</p>
  
  <p>But while  I am using <code>ng serve --environment=mock</code> the Save Cart functionality is not working because of POST call. (All the GET call is working fine)</p>
  
  <p>Actually I need to setup the structure in such a way that, </p>
  
  <ol>
  <li>using <code>ng serve</code>. I could switch to original implementation which will use original service end points.</li>
  <li>using <code>ng serve --environment=mock</code> I could switch to mock implementation which will uses JSON files.</li>
  <li>At the time of switching I do not need to touch any code. For mock implementation a set of predefined data will be serve always since my JSON file is hard coded.</li>
  </ol>
  
  <p><strong>Note:</strong>
  I have updated the main question to clarify the context what I am looking for.
  Same kind of error I am getting in this following <a href="https://plnkr.co/edit/f6yJHsqRdfPk8xEC33t9?p=preview" rel="nofollow noreferrer">Plunker</a> (Please check console log). But note: this plunker does not implements the emvironments, so solving this plunker may not solve my problem.</p>